Visual Studio 2015. Outlook 2016.
I want to write a plug-in that replaces certain forms of text with a hyperlink while looking at the email in either the reading pane or an Inspector.
I can subscribe to the ItemLoad event:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemLoad += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemLoadEventHandler(OnItemLoad);
}
private void OnItemLoad(object item)
{
Outlook.MailItem mailItem = item as Outlook.MailItem;
if (mailItem != null)
{
System.Diagnostics.Debug.WriteLine("OnItemLoad: " + mailItem.Subject);
}
}
But when it is fired for some reason I can't access anything on the Outlook.MailItem instance. I get the following exception:
An exception of type 'System.Runtime.InteropServices.COMException' occurred in FirstOutlookAddIn.dll but was not handled in user code
Additional information: The item’s properties and methods cannot be used inside this event procedure.
Thanks in advance!