Handling New Email event or open/reply/forward mail event
Hello All,
I am creating an Outlook Add-in using VSTO and would like to know what is the best way of handling "New Mail" or "Forward" or "Reply" events.
The code must also execute when using the "Send To --> Mail Recipient" from the windows explorer.
I have posted the code below but this does not seem to work when I try sending an email using "Send To --> Mail Recipient" or from any other application.
Thanks.
privatevoid ThisApplication_Startup(object sender,EventArgs e)
{
Outlook.NameSpace ns =this.Session;
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
inspectors =this.Inspectors;
inspectors.NewInspector +=new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
try
{
Object item = Inspector.CurrentItem;
if (itemis Outlook.MailItem)
{
mi = itemas Outlook.MailItem;
mi.Read +=new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReadEventHandler(mi_Read);
mi.Open +=new Microsoft.Office.Interop.Outlook.ItemEvents_10_OpenEventHandler(mi_Open);
}
}
catch (Exception ex)
{
}
}
// This event occurs when a new mail is created
void mi_Open(refbool Cancel)
{
if (mi.Sent ==false)
{
}
}

