public partial class ThisAddIn { private Outlook.Explorers _Explorers; // the Outlook Explorers collection private Outlook.Inspectors _Inspectors; // the Outlook Inspectors collection private Outlook.NameSpace outlookNamespace; private Outlook.Application outlookObj; private void ThisAddIn_Startup(object sender, System.EventArgs e) { _Explorers = this.Application.Explorers; _Inspectors = this.Application.Inspectors; _Explorers.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx); // this.Application.ItemLoad += //new Outlook.ApplicationEvents_11_ItemLoadEventHandler(GetMailItemLocation); outlookNamespace = this.Application.GetNamespace("MAPI"); } private void Application_NewMailEx(string EntryID) { Outlook.MailItem newMail = (Outlook.MailItem)_Explorers.Application.Session.GetItemFromID( EntryID, System.Reflection.Missing.Value); string Path = @"C:\Temp\" + newMail.Subject + ".msg"; //Alternate way string uPath = @"C:\Temp\"; newMail.SaveAs(Path, Outlook.OlSaveAsType.olMSG); newMail.SaveAs(uPath, Outlook.OlSaveAsType.olMSG); if (newMail.Subject != null) { MessageBox.Show("From: " + newMail.SenderEmailAddress + "\nSubject: " + newMail.Subject, "New Email", MessageBoxButtons.OK); } else { MessageBox.Show("You've got mail."); } } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { _Explorers = null; _Inspectors = null; GC.Collect(); GC.WaitForPendingFinalizers(); } private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)