I am attempting to write an AddIn that can modify an Outlook MailItem when it is loaded (either through a preview pane or through it being opened). Here is the code that I have so far, but I can't seem to actually access the MailItem
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, EventArgs e)
{
Application.ItemLoad += ApplicationOnItemLoad;
}
private void ApplicationOnItemLoad(object item)
{
var mail = item as MailItem;
if (mail != null)
{
Console.WriteLine(mail.HTMLBody);
}
}
// Etc...
}
The code reaches the Console.WriteLine(mail.HTMLBody);
statement just fine, meaning that casting the item as an Outlook MailItem is fine (it doesn't end up being null). However, I can't access any of the MailItem members... it just throws exceptions:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in MyOutlookProject.DLL
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll