Пример #1
0
 /// <summary>
 /// Adds a header to a mailitem
 /// </summary>
 /// <param name="mailItem"></param>
 /// <param name="header"></param>
 /// <param name="value"></param>
 private void AddHeader(Microsoft.Office.Interop.Outlook._MailItem mailItem, string header, string value)
 {
     if (null != mailItem)
     {
         mailItem.PropertyAccessor.SetProperty(string.Format("{0}/{1}", MimePropertySchema, header), value);
     }
 }
Пример #2
0
        public void forward_Click(IRibbonControl control)
        {
            if (null == Globals.ThisAddIn.ForwardingSubject || string.IsNullOrEmpty(Globals.ThisAddIn.ForwardingSubject) ||
                null == Globals.ThisAddIn.ForwardingBody || string.IsNullOrEmpty(Globals.ThisAddIn.ForwardingBody))
            {
                MessageBox.Show("Plugin is not configured.", "Error");
                return;
            }

            try
            {
                if (Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count <= 0)
                {
                    return;
                }

                if (MessageBox.Show("Send selected mail?", "Send", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }

                Microsoft.Office.Interop.Outlook._MailItem mi = (Microsoft.Office.Interop.Outlook._MailItem)Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                mi.Subject = Globals.ThisAddIn.ForwardingSubject;
                mi.Body    = Globals.ThisAddIn.ForwardingBody;
                mi.Recipients.Add(Globals.ThisAddIn.ForwardingAddress);
                foreach (Microsoft.Office.Interop.Outlook.MailItem mailitem in Globals.ThisAddIn.Application.ActiveExplorer().Selection)
                {
                    while (mailitem.Attachments.Count > 0)
                    {
                        mailitem.Attachments.Remove(1);
                    }

                    mi.Attachments.Add(mailitem);
                }

                if (null != Globals.ThisAddIn.ForwardingMimeHeader && !string.IsNullOrEmpty(Globals.ThisAddIn.ForwardingMimeHeader) &&
                    null != Globals.ThisAddIn.ForwardingMimeValue && !string.IsNullOrEmpty(Globals.ThisAddIn.ForwardingMimeValue))
                {
                    AddHeader(mi, Globals.ThisAddIn.ForwardingMimeHeader, Globals.ThisAddIn.ForwardingMimeValue);
                }

                mi.Send();

                MessageBox.Show("The message(s) has been forwarded.");
            }
            catch (Exception ex)
            {
                Globals.ThisAddIn.LogMessage(ex.Message, ex.StackTrace);
                if (Globals.ThisAddIn.ShowPopups)
                {
                    MessageBox.Show("An error occurred, check the eventlog for detailed information.");
                }
            }
        }
Пример #3
0
        public void forward_Click(IRibbonControl control)
        {
            try
            {
                if (Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count <= 0)
                {
                    return;
                }
                MessageBoxControlBox controlUI = new MessageBoxControlBox();
                controlUI.ShowDialog();
                if (controlUI.DialogResult == true)
                {
                    Microsoft.Office.Interop.Outlook._MailItem mi = (Microsoft.Office.Interop.Outlook._MailItem)Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                    mi.Subject = Globals.ThisAddIn.ForwardingSubject;
                    mi.Body    = Globals.ThisAddIn.ForwardingBody;
                    mi.Recipients.Add(Globals.ThisAddIn.ForwardingAddress);
                    foreach (Microsoft.Office.Interop.Outlook.MailItem mailitem in Globals.ThisAddIn.Application.ActiveExplorer().Selection)
                    {
                        while (mailitem.Attachments.Count > 0)
                        {
                            mailitem.Attachments.Remove(1);
                        }
                        mi.Attachments.Add(mailitem);
                        mi.Body = controlUI.Reason;
                    }

                    AddHeader(mi, Globals.ThisAddIn.ForwardingMimeHeader, Globals.ThisAddIn.ForwardingMimeValue);
                    mi.Send();

                    System.Windows.Forms.MessageBox.Show("The message(s) has been forwarded.");
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                Globals.ThisAddIn.LogMessage(ex.Message, ex.StackTrace);
                if (Globals.ThisAddIn.ShowPopups)
                {
                    System.Windows.Forms.MessageBox.Show("An error occurred, check the eventlog for detailed information.");
                }
            }
        }