InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

Custom Mail headers and EWS

The mail headers are exposed on the EmailMessage as first class property: InternetMessageHeaders. However, Exchange also stores each mail header in its own property and defines a unique property set for it: PS_INTERNET_HEADERS.

Here is a property definition for a hypothetical custom property:

private static readonly ExtendedPropertyDefinition FrobProperty =
    new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Frob", MapiPropertyType.String);

If a mail is processed by Exchange with message header like this:

Subject: Test mail
X-Frob: Yes
From: "Henning Krause" <someone@infinitec.de>
To: "Someone <someone@example.local>

Exchange will parse the mail and set the value of the extended property defined above to “Yes”.

Retrieving the custom property is as simple as this:

var item = Item.Bind(service, itemId,
    new PropertySet(BasePropertySet.FirstClassProperties, FrobProperty));

The value of the property can then be accessed using this line:

string frobValue;
if (item.TryGetProperty(FrobProperty, out frobValue))
{
    Console.Out.WriteLine("The item as a frob value of: {0}", frobValue);
}

You can even search for messages which have the header “X-Frob” set to “Yes”:

var itemId = folder.FindItems(new SearchFilter.IsEqualTo(FrobProperty, "yes"), 
    new ItemView(10) {PropertySet = PropertySet.IdOnly});

This query will return the first ten messages which have said header set to “Yes”.

Note that Exchange has a limit for named properties which are the result of custom mail headers. You may get one of these entries in your EventLog at some point:

Event ID: 9666
Type: Warning
Category: General
Source: msgidNamedPropsQuotaWarning
Description: The number of named properties created for database "<database name>" is close to quota limit. Current number of named properties: <number of named properties>. Quota limit for named properties: <configured quota>. User attempting to create the named property: <user name>. Named property GUID: <GUID of named property>. Named property name/id: <name of named property>.

 

Event ID: 9667
Type: Error
Category: General
Source: msgidNamedPropsQuotaError
Description: Failed to create a new named property for database "<database name>" because the number of named properties reached the quota limit (<configured quota>). User attempting to create the named property: <user name>. Named property GUID: <GUID of named property>. Named property name/id: <name of named property>.

 

See this blog post on how to deal with this issue: http://blogs.technet.com/b/exchange/archive/2010/07/29/3410545.aspx.


Posted by Henning Krause on Monday, August 01, 2011 12:00 PM, last modified on Wednesday, July 27, 2011 5:57 PM
Permalink | Post RSSRSS comment feed

 +Pingbacks and trackbacks (1)

Add comment

biuquote
  • Comment
  • Preview
Loading