string sp = @"D:\filescompare"; //Input directory to process comparision // ---Download attchment from outlook unread mail---- //Start Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI"); Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); Microsoft.Office.Interop.Outlook.MailItem newEmail = null; try { foreach (object collectionItem in myInbox.Items.Restrict("[unread]=true")) //foreach (object collectionItem in myInbox.Items.Restrict("[unread]=true")) { newEmail = collectionItem as Microsoft.Office.Interop.Outlook.MailItem; //newEmail = collectionItem as Microsoft.Office.Interop.Outlook.MailItem; if (newEmail != null) { if (newEmail.Attachments.Count > 0) { for (int j = 1; j <= newEmail.Attachments.Count; j++) { newEmail.Attachments[j].SaveAsFile(sp + "\\" + newEmail.Attachments[j].FileName); } } else { Console.WriteLine(); } } } } catch (System.Runtime.InteropServices.COMException ex) { Console.WriteLine(ex.ToString()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)