Beispiel #1
0
        protected override void Execute(CodeActivityContext context)
        {
            Application app = new Application();

            app.ActiveWindow();
            Outlook.MailItem mail;
            if (!(TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg")))
            {
                throw new System.Exception("Invalid template format, please use a '.oft' or '.msg' template.");
            }
            mail = TemplatePath.Get(context) != ""?(app.CreateItemFromTemplate(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)) as Outlook.MailItem):new MailItem();

            mail.Subject = String.IsNullOrEmpty(Subject.Get(context))?(String.IsNullOrEmpty(mail.Subject)?"Untitled":mail.Subject):Subject.Get(context);
            mail.To      = String.IsNullOrEmpty(To.Get(context))?mail.To:To.Get(context);
            mail.CC      = String.IsNullOrEmpty(Cc.Get(context))?mail.CC:Cc.Get(context);
            mail.BCC     = String.IsNullOrEmpty(Bcc.Get(context))?mail.BCC:Bcc.Get(context);
            if (String.IsNullOrEmpty(mail.To) && String.IsNullOrEmpty(mail.CC) && String.IsNullOrEmpty(mail.BCC))
            {
                throw new System.Exception("Error, there is no recepients specified");
            }

            mail.HTMLBody = mail.HTMLBody.Replace("{message}", Body.Get(context));
            mail.HTMLBody = mail.HTMLBody.Replace("{table}", DT.Get(context) != null?(DT.Get(context).Rows.Count > 0?GetHTMLTable(DT.Get(context)):""):"");
            mail.Send();
            app.GetNamespace("MAPI").SendAndReceive(true);

            var releaseResult = Marshal.ReleaseComObject(app);
        }
Beispiel #2
0
 public void ArchiveButton_Click(Office.IRibbonControl control)
 {
     if (_outlook.ActiveWindow() == _outlook.ActiveExplorer())
     {
         HandleExplorerWindow();
     }
     else
     {
         HandleEmailWindow();
     }
 }
        /// <summary>
        /// Parse an opend item if it is a mail
        /// </summary>
        public static void ParseItemForAttachments(object item)
        {
            if (item == null)
            {
                return;
            }

            // is it a mail?
            if (!(item is Outlook.MailItem))
            {
                return;
            }

            // cast to MailItem
            if (!(item is MailItem mailItem))
            {
                return;
            }

            Application app = Globals.ThisAddIn.Application;

            // it is a new one
            if (mailItem.EntryID == null && mailItem.Sent == false)
            {
                // is it a reply?
                bool isReply = !string.IsNullOrEmpty(mailItem.To) || mailItem.Recipients.Count > 0;
                // it is!
                if (isReply)
                {
                    // keep attachments from original mail
                    // get selected item (reply is open, so this should be the original mail)
                    MailItem src = null;
                    if (app.ActiveWindow() is Outlook.Explorer)
                    {
                        //Debug.WriteLine("Explorer");
                        if (app.ActiveExplorer().Selection.Count == 1)
                        {
                            object selectedItem = app.ActiveExplorer().Selection[1];
                            if (selectedItem is Outlook.MailItem)
                            {
                                src = selectedItem as Outlook.MailItem;
                            }
                        }
                    }
                    else
                    if (app.ActiveWindow() is Outlook.Inspector)
                    {
                        //Debug.WriteLine("Inspector");
                        object selectedItem = app.ActiveInspector().CurrentItem;
                        if (selectedItem is Outlook.MailItem)
                        {
                            src = selectedItem as Outlook.MailItem;
                        }
                    }

                    if (src != null)
                    {
                        mailItem.CopyAttachmentsFrom(src);
                    }
                }
            }
        }