I have done some research and also some code testing with Microsoft Exchange Server 2010 to realise that in bounced e-mails, the headers are being removed. One of the articles I referred to was this: Detecting bounced messages by return-path header.
The problem I have is trying retrieve custom headers from bounced e-mail, but it seems impossible according to my research. The other solution that was mentioned in the above article was using the return-path address.
However, when I access my web e-mail using Microsoft Outlook Web App, and checking the e-mail that was bounced back to my address, I was able to view the original message headers. So, is it possible to use EWS managed API to retrieve the original message headers?
The original message header is follows:
Diagnostic information for administrators:
Generating server: MXG001.domain.com
[email protected]
gmail-smtp-in.l.google.com # #SMTP#
Original message headers:
Return-Path: [email protected]
Received: from MXG001.domain.com (unknown [127.0.0.1]) by IMSVA (Postfix)
with ESMTP id 1484C26805C for ;
Wed, 29 Aug 2012 20:07:56 +1000 (EST)
Received: from EZY106 (unknown [10.32.8.141]) by MXG001.domain.com
(Postfix) with ESMTP id 6F7B026805B for
[email protected]; Wed, 29 Aug 2012 20:07:55
+1000 (EST)
Reply-To: [email protected]
X-CustomHeader1: 0E591306-9997-4E35-954E-F36A069AF8B4
X-CustomHeader2: 1F80DCBF-2F93-49A4-90C0-00E79763B916
MIME-Version: 1.0
Sender: domain [email protected]
From: [email protected]
To: [email protected]
Date: Wed, 29 Aug 2012 18:10:13 +0800
Subject: Test e-mail tracking 3
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Message-ID: [email protected]
X-TM-AS-MML: No
X-TM-AS-Product-Ver: IMSVA-8.2.0.1520-6.8.0.1017-19146.000
X-TM-AS-Result: No--0.146-5.0-31-10
X-imss-scan-details: No--0.146-5.0-31-10
X-TM-AS-User-Approved-Sender: No
X-TMASE-Version: IMSVA-8.2.0.1520-6.8.1017-19146.000
X-TMASE-Result: 10--0.146400-5.000000
X-TMASE-MatchedRID: wjdoQEOKyrZ7ahiNncA4hJpaQZrxtVBsqS91SjnldFIi7hIFpWx7pqbF
sETXF+9u5V8fgkZZSCU19vcvk7TH/S8xkUATmhC45BgEdUqqANSV8bCk1I9WfnXA+T8YcZkDP/i
gW2j9KQ2dtSjAL+46o1q6LJohGEOtW5fzCBTKbRONes9LMglhgLejw9iqfGUKR0givuLhSAhBg2
NqmDTb6Q+gzceqIagHXcAUO5rYRMutSn//sy4xSbAVy0FQT/1xloKBPsyyeoXpAAWYDGUZn3OxN
uYzUrAfNmDrdAkjVfe9KhpQKnl6nw==
I use the code below to write a client to access EWS which works fine as well. So my only problem is if it is possible to retrieve the original message header? If so, how can I do it? Thanks!
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials(@"myUsername", "myPassword");
service.Url = new Uri("https://webmail.domain.com/ews/exchange.asmx");
Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
SearchFilter sf = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "REPORT.IPM.Note.NDR");
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter[] { sf });
ItemView view = new ItemView(20);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
foreach (EmailMessage item in findResults)
{
// Can process whatever is necessary here
}
In 2022, To me it seems you are missing this line to load Message headers. EWS being a lightweight service it doesn't load all the info(like body/header) so you need load it with the below line.
item.Load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.InternetMessageHeaders));
so that it looks something like this:
foreach (EmailMessage item in findResults)
{
item.Load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.InternetMessageHeaders));
//Then item.InternetMessageHeaders will be populated
Console.WriteLine(item.InternetMessageHeaders);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With