In order to read the header a mail item in Outlook, I found the following solution for Outlook 2010 but it does not work with Outlook 2019 (and probably also not with Outlook 365).
var mailItem = item as MailItem;
if (mailItem != null)
{
var header = mailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E/");
...
Unfortunately I receive this error message:
System.ArgumentException: 'The property "http://schemas.microsoft.com/mapi/proptag/0x007D001E/" cannot be parsed or has an invalid format.'
So, how to read the header of an e-mail using C# and VSTO? What is considered to be best practice?
The DASL name is invalid - you have an extra trailing "/"
. Use "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
.
Be prepared to handle "not found" errors - no MAPI property is guaranteed to be present.
If you want to see DASL property names for existing properties, take a look at a message with that property set with OutlookSpy (I am its author) - click IMessage button, select the property, copy the value of the DASL edit box.