Listing 1 Getting the Application object
applicationObject = (Outlook.Application)application;
//At class level
private static Outlook.Application applicationObject;
/public static Outlook.Application ApplicationObject
{ get{ return applicationObject; } }
Listing 2 Registering for the NewInspector event
applicationObject.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
Listing 3 Handling the NewInspector event
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
try
{
if(Inspector.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem currMailItem = (Outlook.MailItem)Inspector.CurrentItem;
if(!currMailItem.Sent)
{
System.Diagnostics.Debug.WriteLine("New Mail Item!");
}
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
Listing 4 Updated NewInspector event registration
inspectors = Connect.applicationObject.Inspectors;
inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
Listing 5 EmailWrapper constructor code
mailItem.Open += new Outlook.ItemEvents_10_OpenEventHandler(mailItem_Open);
((Outlook.ItemEvents_Event)mailItem).Close += new Outlook.ItemEvents_CloseEventHandler(mailItem_Close);