public String CDOGetSubjects() { MAPI.Session objSession = new MAPI.Session(); String retVal = ""; // Missing.Value represents a default argument object objEmpty = Missing.Value; // Logon the session using CDO's UI objSession.Logon(objEmpty, objEmpty, true, true, 0, true, objEmpty); MAPI.Folder objInbox = (MAPI.Folder)objSession.Inbox; MAPI.Messages objMessages = (MAPI.Messages)objInbox.Messages; MAPI.Message objMessage = (MAPI.Message)objMessages.GetFirst(objEmpty); while (objMessage is MAPI.Message) { retVal += objMessage.Subject.ToString(); objMessage = (MAPI.Message)objMessages.GetNext(); if (objMessage is MAPI.Message) { retVal += "\r\n"; } } return(retVal); }
public static bool GetFile(string filename, DateTime date) { //Log.WriteLine("Create MAPI Session"); try { MAPI.Session oSession = new MAPI.Session(); //Log.WriteLine("Created MAPI Session"); // Will use vEmpty for Empty parameter Object vEmpty = System.Reflection.Missing.Value; //setup profile string strProfileInfo = "NIGHTCRAWLER.maplenj.com" + "\n" + "SLLists"; // Logon //Log.WriteLine("Loging in"); oSession.Logon("SLLists", "welcome", false, true, 0, true, strProfileInfo); //Log.WriteLine("Logged in"); //get inbox MAPI.Folder inbox = (MAPI.Folder)oSession.Inbox; //get the processed folder MAPI.Folders oFolders = (MAPI.Folders)inbox.Folders; MAPI.Folder processedFolder = (MAPI.Folder)oFolders.get_Item("Processed"); // Get Messages collection. MAPI.Messages oMsgs = (MAPI.Messages)inbox.Messages; //process the collection for (int i = 0; i < (int)oMsgs.Count; i++) { MAPI.Message msg = (MAPI.Message)oMsgs.get_Item(i + 1); if (DateTime.Parse(msg.TimeReceived.ToString()) >= date.Date) { MAPI.Attachments atm = (MAPI.Attachments)msg.Attachments; // modified to check all attachments for (int j = 0; j < (int)atm.Count; j++) { MAPI.Attachment a = (MAPI.Attachment)atm.get_Item(j + 1); if (a.Name.ToString().ToUpper() == filename.ToUpper()) { //Log.WriteLine("Saving file"); a.WriteToFile(System.AppDomain.CurrentDomain.BaseDirectory + Properties.Settings.Default.ImportDir + DateTime.Today.ToString("yyyyMMdd") + "_" + a.Name); //a.WriteToFile(@"C:\" + a.Name); // remove //Log.WriteLine("Saved file"); return true; } } } } // Log off session. if (oSession != null) oSession.Logoff(); } catch (Exception e) { //Log.WriteLine(e.ToString()); } return false; }