Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to create a Add In in which i have to read mails inside a particular folder of Outlook (like Inbox->TestFolder)and then transfer that mail to webserver. i have created a rule to move mails to TestFolder.
I am able to fire NewMailEx event but i am not able to read mails inside test folder since NewMailEx fires before rules process
Please help me on this if possible with some code

or can i use window service for the same ,what will be the better option Window service or outlook Addin


C#
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);
                    }
                }
            }

            
        }
Posted
Updated 13-Nov-11 22:14pm
v2

1 solution

Why don't you perform the mail-move-to-folder action as part of your event, instead of a rule? In this case, you can be certain that all messages you want are in the target folder...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900