private void ThisAddIn_Startup(object sender, System.EventArgs e) { _Explorers = this.Application.Explorers; _Explorers.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx); }
private void Application_NewMailEx(string EntryID) { Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null; Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null; outlookNamespace = this.Application.GetNamespace("MAPI"); outlookNamespace.Logon(null, null, false, false); inboxFolder = outlookNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); subFolder = inboxFolder.Folders["HR"]; foreach (Microsoft.Office.Interop.Outlook.MailItem mail in subFolder.Items) { if (mail.UnRead == true) { foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mail.Attachments) { filename = folderpath + attachment.FileName; attachment.SaveAsFile(filename); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)