Custom Header in ExchangeMessageInfo

Hello,

I added a custom header in the message that gets included with no problem now:

To: luisgneut@gmail.com
ReferenceNumber: 7553.10.12/8/2015
Date: Tue, 8 Dec 2015 19:04:25 +0000
MIME-Version: 1.0
Message-ID: <20151208190431.205D3AF1171@mailgate3.....>

The issue I have is that it does not show in your headers collection when reading the message

  1. Could you provide me a code example where I get that custom header value utilizing Exchange service utilzing something like
IEWSClient ewsClient = EWSClient.GetEWSClient(mailboxUri, credential);

It does not show in the headers here:

foreach (ExchangeMessageInfo msgInfo in messages)
{
   MailMessage msg = ewsClient.FetchMessage(msgInfo.UniqueUri);
   var headers = msg.Headers;
   
   foreach (var header in msg.Headers.AllKeys)
   {
      System.Diagnostics.Debug.WriteLine(string.Format("{0}: {1}", header, msg.Headers[header]));
   }

So again how can I get that custom header value utilizing IEWSClient shown above?

Thanks

Luis

Kay I even added the code as it is in another of your posts and nothing the custom header does not show in the collection. The email header now has:

To: luisgnbbbbbbt@gmail.com
MyId: 7553
Date: Wed, 9 Dec 2015 22:52:03 +0000
MIME-Version: 1.0
Message-ID: <20151209225203.2037AB15942@mailgate3...>

The code was modified to include your recommendation from another post

foreach (ExchangeMessageInfo msgInfo in messages)
{
   MailMessage msg = ewsClient.FetchMessage(msgInfo.UniqueUri);
   
   if (!string.IsNullOrEmpty(msg.Headers["MyId"]))
      System.Diagnostics.Debug.WriteLine("***MyId*** " + msg.Headers["MyId"]);
   
   var headers = msg.Headers;
   
   foreach (var header in msg.Headers.AllKeys)
   {
      System.Diagnostics.Debug.WriteLine(string.Format("{0}: {1}", header, msg.Headers[header]));
   }
}

And yet it never goes inside the if statement and the custom header seems to be nowhere to be found

I will appreciate if you let me know how can I retrieve the customer header again utilizing

IEWSClient ewsClient = EWSClient.GetEWSClient(mailboxUri, credential);

and code similar to the one above. I am utilizing Exchange 2010

Thank you

Hi Luis,

All the custom headers are retained till the message is residing oon the disc. As soon as it is sent, Exchange server re-writes all the headers and custom headers are removed. That is why these cannot be fetched on the receving end.

You may use some attachment or guid in the subject/body as these are not truncated by the Exchange. Please feel free to write us back if you have any other query in this regard.