r.mcleay

r.mcleay

  • NA
  • 1
  • 0

MAPI Inbox watcher

Sep 11 2003 10:34 PM
I am trying to build an app to watch an exchange server to locate specific attachement, namely xml documents. Using MAPI it appears that the file name of the attachment is trunctated to 8 characters (8.3 Format). Using CDO 1.21 I am not able to log in to the server propertly, ther are no errors occuring, it is asking for user name and password and for all I can tell it checking the server, but not finding any emails. At this point I am only trying to list the attachment names. I am new to C# and would very much appreciate anyone with any experience in MAPI/CDO and C# to have a look at my code. Solution 1: Using the MAPI Component This will only provide a truncated(8.3) attachment file name which does not suit my needs label1.Text = string.Empty; axMAPISession1.DownLoadMail = true; axMAPISession1.SignOn(); axMAPIMessages1.SessionID = axMAPISession1.SessionID; axMAPIMessages1.Fetch(); for ( int i=0; i< (int) axMAPIMessages1.MsgCount; i++) { axMAPIMessages1.MsgIndex = i; for (int j=0; j< (int)axMAPIMessages1.AttachmentCount; j++) { //List the attachment names label1.Text += axMAPIMessages1.AttachmentName + "\n"; } } axMAPISession1.SignOff(); Solution 2: Using CDO 1.2.1 This can access the full attachment filename (So I'm Told) but I am unable to get it to log in to an exchange inbox. MAPI.Session objSession; MAPI.Folder objFolder ; MAPI.Messages objMessageList; MAPI.Message objMessage; MAPI.Attachments objAttachmentList; MAPI.Attachment objAttachment; MAPI.MessageFilter objFilter; objSession = new MAPI.SessionClass(); // Logon to the Exchange Server using Internet Mail method and profile objSession.Logon("MYADMINPROFILENAME", "MYADMINPASSWORD", false, false, 0, true, "MYMAILSERVER\nMYADMINPROFILENAME"); objFolder = (MAPI.Folder) objSession.Inbox; objMessageList = (MAPI.Messages) objFolder.Messages; //Set filter to get all unread mail objFilter = (MAPI.MessageFilter) objMessageList.Filter; objFilter.Unread = true; objMessage = (MAPI.Message) objMessageList.GetFirst(objFilter); if((int) objMessageList.Count == 0)//objMessage Is Nothing { label2.Text = "No Mail:" + System.DateTime.Now; } else //Never made it to here { //("You've got mail") //' Loop until all mail are read for (int i=0; i<(int)objMessageList.Count; i++) { objAttachmentList = (MAPI.Attachments) objMessage.Attachments; for (int j=0; j<(int)objAttachmentList.Count; j++) { objAttachment = (MAPI.Attachment) objAttachmentList.get_Item(j); //label2.Text += objAttachment.Fields(CdoPR_ATTACH_LONG_FILENAME) + "\n"; label2.Text += objAttachment.Name + "\n"; } } } I am new to c# so please point out the obvious. I feel the main problem with the CDO 1.2.1 is the logging in. With the MAPI Component I don't think the full file name is available, please tell me if I am wrong. PS No errors are occuring in the code. It just does not do what I want it to. Thanks for your time to read my problem