PropertyAccessor in Exchange 2010 – issue and some workarounds

Following code works fine in Exchange 2003 and 2007. But fails in Exchange 2010, that too in Online Mode. There is an interesting discussion that happened recently in MSDN Forums on this topic. Just would like to share summary of it so that it will be helpful to them who are in need of it.

As of now, there is not work around, except changing mode of Exchange to Cache Mode. Some told that Microsoft is aware of this issue and working on it. A fix may be released with the next patches.

const string TEST_PROPERTY = @"http://schemas.microsoft.com/mapi/string/
{00020329-0000-0000-C000-000000000046}/TestProperty/00000003";
 const int TEST_VALUE = 9;
 application = new MSOutlook.ApplicationClass();
 email =
(MSOutlook.MailItem)application.CreateItem(MSOutlook.OlItemType.olMailItem);
 propertyAccessor = email.PropertyAccessor;
 propertyAccessor.SetProperty(TEST_PROPERTY, TEST_VALUE);
 object objValue = propertyAccessor.GetProperty(TEST_PROPERTY);

Here is another work around suggested by Joel…

“it looks like the it’s not completely resolved by simply using extended MAPI.  I was trying to use IMAPIProps::GetProps() and specifying a single property tag with the ID specified, but the type not specified (using PT_UNSPECIFIED).  As already noted, this works fine with Exchange 2007 online or cached mode, Exchange 2010 in cached mode, but not in Exchange 2010 online mode.

The workaround in this case is to specify the correct property type.  But, since the managed PropertyAccessor.GetProperty() method does not know what the property type is ahead of time (at least for custom properties), I guess that could be why it’s failing.  What I’m doing now is calling IMAPIProp::GetPropList() and finding the entry with matching property tag.  Since GetPropList() returns the property type as well, I can now call GetProps() with the correct property type.  This seems to work in Exchange 2010 online mode :)”

I think this is the simplest of all (which is suggested by Susanne Kapp via Wompi)…

For an easy workaround in VSTO, you can simply call the mailItem.Save() method after setting the property. But be aware of all the mails getting saved to your drafts folder if you don´t send the mail.

Hope this helps!