1

我目前正在从OpenPop迁移到MailKit

我有一个单元测试,可以将字符串加载到 MimeMessage 中,如下所示:

var emailText = @"
X-MDAV-Processed: mx1.footechnology.com.au, Mon, 30 Mar 2015 12:54:30 +1100
Return-path: <do-not-reply@baz.com.au>
Received: from mail2.baz.com.au (mail2.baz.com.au [220.157.74.146])
    by mx1.footechnology.com.au (mx1.footechnology.com.au)
    (MDaemon PRO v11.0.3)
    with ESMTP id md50005410292.msg
    for <faxes@foobar.com.au>; Mon, 30 Mar 2015 12:54:29 +1100
Authentication-Results: mx1.footechnology.com.au
    spf=neutral smtp.mail=do-not-reply@baz.com.au;
    x-ip-ptr=pass dns.ptr=mail2.baz.com.au (ip=220.157.74.146);
    x-ip-helo=pass smtp.helo=mail2.baz.com.au (ip=220.157.74.146);
    x-ip-mail=pass smtp.mail=do-not-reply@baz.com.au (ip=220.157.74.146)
Received-SPF: none (mx1.footechnology.com.au: do-not-reply@baz.com.au does not
    designate permitted sender hosts)
    x-spf-client=MDaemon.PRO.v11.0.3
    receiver=mx1.footechnology.com.au
    client-ip=220.157.74.146
    envelope-from=<do-not-reply@baz.com.au>
    helo=mail2.baz.com.au
X-Spam-Processed: mx1.footechnology.com.au, Mon, 30 Mar 2015 12:54:29 +1100
    (not processed: sender do-not-reply@baz.com.au in exclude file)
X-MDPtrLookup-Result: pass dns.ptr=mail2.baz.com.au (ip=220.157.74.146) (mx1.footechnology.com.au)
X-MDHeloLookup-Result: pass smtp.helo=mail2.baz.com.au (ip=220.157.74.146) (mx1.footechnology.com.au)
X-MDMailLookup-Result: pass smtp.mail=do-not-reply@baz.com.au (ip=220.157.74.146) (mx1.footechnology.com.au)
X-MDDK-Result: neutral (mx1.footechnology.com.au)
X-MDDKIM-Result: neutral (mx1.footechnology.com.au)
X-MDSPF-Result: none (mx1.footechnology.com.au)
X-Rcpt-To: faxes@foobar.com.au
X-MDRcpt-To: faxes@foobar.com.au
X-MDRemoteIP: 220.157.74.146
X-Return-Path: do-not-reply@baz.com.au
X-Envelope-From: do-not-reply@baz.com.au
X-MDaemon-Deliver-To: faxes@foobar.com.au
Received: from melbourne.baz.com.au (melbourne.baz.com.au [118.88.188.238])
    by mail2.baz.com.au (Postfix) with ESMTP id 3E100437181
    for <faxes@foobar.com.au>; Mon, 30 Mar 2015 11:54:17 +1000 (EST)
Received: from baz.com.au (localhost [127.0.0.1])
    by melbourne.baz.com.au (Postfix) with ESMTP id 6BA057C07C
    for <faxes@foobar.com.au>; Mon, 30 Mar 2015 12:54:16 +1100 (EST)
Content-Transfer-Encoding: binary
Message-ID : <syd1_did11-1403160784-288657210-5-21314.1403160831@medora2.syd1.colo.j2noc.com>
Content-Type: multipart/mixed; boundary=""_----------=_1301450056175850""
MIME-Version: 1.0
X-Mailer: MIME::Lite 3.01 (F2.72; B3.04; Q3.03)
Date: Mon, 30 Mar 2015 01:54:16 UT
From: ""Baz"" <do-not-reply@baz.com.au>
To: ""Foo Bar"" <fax@foobar.com.au>

This is a multi-part message in MIME format.

--_----------=_1301450056175850
Content-Disposition: inline
Content-Length: 1133
Content-Transfer-Encoding: binary
Content-Type: text/plain

This is the content of the message.

--_----------=_1301450056175850
Content-Disposition: attachment; filename=""fax-20110330125416.pdf""
Content-Transfer-Encoding: base64
Content-Type: application/pdf; name=""fax-20110330125416.pdf""

JVBERi0xLjEgDSXi48/TDQoxIDAgb2JqDTw8IA0vVHlwZSAvQ2F0YWxvZyAN

--_----------=_1301450056175850--
";

            var stream = new MemoryStream(Encoding.UTF8.GetBytes(emailText));
            var message = MimeMessage.Load(stream);

            Console.WriteLine("Text body:" + message.TextBody);
            Console.WriteLine("Html body:" + message.HtmlBody);
            Console.WriteLine("Date:" + message.Date);
            Console.WriteLine("MessageId:" + message.MessageId);
            Console.WriteLine("From:" + message.From.Mailboxes.First().Address);
            Console.WriteLine("To:" + message.To.Mailboxes.First().Address);

成功解析消息时,找不到 MessageId 标头。OpenPop 可以在电子邮件中找到 MessageId。为什么 MailKit 会失败?消息 id 标头是否以某种方式被视为无效并被丢弃?

4

1 回答 1

1

问题是 ':' 字符之前的额外空间:

Message-ID : <syd1_did11-1403160784-288657210-5-21314.1403160831@medora2.syd1.colo.j2noc.com>

于 2015-02-11T00:25:57.607 回答