Tuesday, February 22, 2011

Code to capture the Message arrived event in Outlook

There may be times when we want to do some operation upon arrival of the message in the Outlook Inbox. Here is the simple piece of code which will help to capture the message arrived event in Outlook.

//Initialization code
protected override bool DoInitialise()
{
outlook = new ApplicationClass();
outlook.Session.Logon(null, null, false, false);
inbox = outlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Items;
inbox.ItemAdd += new ItemsEvents_ItemAddEventHandler(inbox_ItemAdd);
outlook.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outlook_NewMailEx);
return true;
}


void outlook_NewMailEx(string EntryIDCollection)
{
//This event will be fired whenever a mail arrives in Inbox
}

No comments:

Post a Comment