PDA

View Full Version : Automatic Detection of Mail Status in Outlook using MAPI


JygzIsHere
04-01-2009, 01:08 AM
Hi To All,

Is there a way in MAPI or others to detect that the mail status is changed, like read or unread.

I want to make a program that runs as a service and a portion of a code will get executed once the current user clicks on an email from his outlook. Like for example when he reads a new email, he will need to click on subject so the new status of the email is changed to "READ" from the time he clicks on the subject a portion of my program will run.

Is it possible? And can you show me a bit on how to do that?

Any ideas is greatly appreciated.

Thanks so much.

-Jan Jerell

JygzIsHere
04-02-2009, 02:01 AM
I find a solution:


Outlook.Application objO = new Outlook.Application();
Outlook.NameSpace objNS = objO.GetNamespace("mapi");
objNS.Logon("PROFILENAME", "PASSWORD", true, false);
Outlook.Folder objFolder = (Outlook.Folder)objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
objFolder.Items.ItemChange +=new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);


void Items_ItemChange(object Item)
{

Outlook.MailItem item = (Outlook.MailItem)Item;

if(item.UnRead)
{
//Email is not yet read
}
else
{
//Email is read
}

}