使用EWS获取原始邮件标题以获取退回的电子邮件

时间:2012-08-29 10:56:26

标签: c# email c#-4.0 exchangewebservices

我已经做了一些研究,并且还使用Microsoft Exchange Server 2010进行了一些代码测试,以实现在退回的电子邮件中,标题正在被删除。我提到的其中一篇文章是:Detecting bounced messages by return-path header

我遇到的问题是尝试从退回的电子邮件中检索自定义标题,但根据我的研究,这似乎是不可能的。上面文章中提到的另一个解决方案是使用返回路径地址。

但是,当我使用Microsoft Outlook Web App访问我的Web电子邮件,并检查退回到我的地址的电子邮件时,我能够查看原始邮件标题。那么,是否可以使用EWS托管API来检索原始邮件头?

原始邮件标题如下:

Diagnostic information for administrators:

    Generating server: MXG001.domain.com

    email.that.do.not.exist.1234567890@gmail.com
    gmail-smtp-in.l.google.com # #SMTP#

    Original message headers:

    Return-Path: sender@domain.com
    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.that.do.not.exist.1234567890@gmail.com; Wed, 29 Aug 2012 20:07:55
     +1000 (EST)
    Reply-To: myemail@domain.com
    X-CustomHeader1: 0E591306-9997-4E35-954E-F36A069AF8B4
    X-CustomHeader2: 1F80DCBF-2F93-49A4-90C0-00E79763B916
    MIME-Version: 1.0
    Sender: domain sender@domain.com
    From: myemail@domain.com
    To: email.that.do.not.exist.1234567890@gmail.com
    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: 20120829100755.6F7B026805B@MXG001.domain.com
    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==
    

我使用下面的代码编写一个客户端来访问EWS,它也可以正常工作。 所以我唯一的问题是,是否可以检索原始邮件标题?如果是这样,我该怎么办?谢谢!

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                  
}

0 个答案:

没有答案