I'm using EWS to interact with Exchange. When I find an incoming email I set a custom extended property on that message to correlate with an ID in my database. That property is saved to exchange and I can retrieve the value later when querying exchange. But I can't see the header when I open the item in Outlook: it's not listed in the email properties. Is there something special I need to do for this to be visible?
Here's my code:
var propertyDefinition = new ExtendedPropertyDefinition(
DefaultExtendedPropertySet.InternetHeaders, "X-My-Property",
MapiPropertyType.String);
// retrieve the item from ExchangeService.FindItems() var item = ...
// Set the property on the exchange item
item.SetExtendedProperty(propertyDefinition, myId.ToString());
// Update the server
item.Update(ConflictResolutionMode.AlwaysOverwrite);
Now when I look at the item in exchange I'd expect to see 'X-My-Property' in the headers, but I don't.
I can retrieve the value, for which I'm using this code:
foreach (var prop in item.ExtendedProperties)
{
if (prop.PropertyDefinition.Name == "X-My-Property" && prop.Value != null)
{
return propValue = prop.Value.ToString();
}
}
If I use the same code to set the property on a new email that I send then I do see the property when that email is received. i.e. not on the message in Sent Items but in the one that arrives in someone's Inbox.
The only time the MIME header will be updated is during a Send or Receive of the Message. All your code is doing is setting an Extended property (which would then be promoted to the Message Header on send) there is more of explanation here https://msdn.microsoft.com/en-us/library/office/hh545614(v=exchg.140).aspx
What you see in Outlook is the PR_Transport_headers property which you could modify also but that won't affect the MIME Content. Why is important that you be able to see the property it should always be accessible via EWS anyway.