/// <summary> /// Get and return the selected item. If it isn't a mail item return null /// </summary> /// <returns></returns> private Outlook.MailItem GetSelectedItem() { var olapp = new Microsoft.Office.Interop.Outlook.Application(); Object selObject = olapp.ActiveExplorer().Selection[1]; if (selObject is Microsoft.Office.Interop.Outlook.MailItem) { return(selObject as Outlook.MailItem); } else { return(null); } }
/// <summary> /// Forward the selected mail /// </summary> private void ForwardMail() { if (!String.IsNullOrEmpty(email)) { var olapp = new Microsoft.Office.Interop.Outlook.Application(); Object selObject = olapp.ActiveExplorer().Selection[1]; if (selObject is Microsoft.Office.Interop.Outlook.MailItem) { Outlook.MailItem mailItem = this.GetSelectedItem(); if (mailItem != null) { mailItem.Recipients.Add(this.email); mailItem.Send(); } } } else { MessageBox.Show("Email isn't configured"); } }