使用 Mailkit 丢失附件
Missing attachments using Mailkit
当我使用 MailKit 通过 IMAP 协议从 Exchange 收到一封带有附件的邮件时,它丢失了附件。
当我这样做时:
string.Format("Mail has {0} attachments", mime.Attachments.Count())
它报告“0”,即使邮件本身包含附件(如果我在 Outlook 客户端中打开它,我会看到附件),当我激活 IMAP 协议日志记录时,很明显它包含一个附件:
S: X-MS-Has-Attach: yes
...
S: Content-Type: message/rfc822
S: Content-Disposition: attachment;
S: creation-date="Thu, 07 Jan 2016 09:16:53 GMT";
S: modification-date="Thu, 07 Jan 2016 09:16:53 GMT"
...
S: X-MS-Has-Attach:
...
有趣的是附件部分的 "S: X-MS-Has-Attach:" header,在来自服务器的同一个包中。
这是已知问题吗?如何解决才能避免在这些情况下遗漏附件?它似乎只发生在某些邮件上并且随机发生。
使用:
MailKit 1.0.14.0
MimeKit 1.0.13.0
我发现有新的更新,但如果这样还是不能解决问题我就不更新了
在您使用的 MimeKit 版本中,MimeMessage.Attachments
是 IEnumerable<MimePart>
,但是 message/rfc822 部分由 MessagePart
表示,它不包含 class MimePart
,它 subclass 是 MimeEntity
(这是 MimePart
的基础 class)。
在较新的版本中,MimeMessage.Attachments
改为 IEnumerable<MimeEntity>
,因此将包括您的 message/rfc822 附件。
您可以通过使用 BodyParts
属性 而不是 Attachments
属性.
在您的 MimeKit 版本中解决此问题
当我使用 MailKit 通过 IMAP 协议从 Exchange 收到一封带有附件的邮件时,它丢失了附件。 当我这样做时:
string.Format("Mail has {0} attachments", mime.Attachments.Count())
它报告“0”,即使邮件本身包含附件(如果我在 Outlook 客户端中打开它,我会看到附件),当我激活 IMAP 协议日志记录时,很明显它包含一个附件:
S: X-MS-Has-Attach: yes
...
S: Content-Type: message/rfc822
S: Content-Disposition: attachment;
S: creation-date="Thu, 07 Jan 2016 09:16:53 GMT";
S: modification-date="Thu, 07 Jan 2016 09:16:53 GMT"
...
S: X-MS-Has-Attach:
...
有趣的是附件部分的 "S: X-MS-Has-Attach:" header,在来自服务器的同一个包中。
这是已知问题吗?如何解决才能避免在这些情况下遗漏附件?它似乎只发生在某些邮件上并且随机发生。
使用: MailKit 1.0.14.0 MimeKit 1.0.13.0
我发现有新的更新,但如果这样还是不能解决问题我就不更新了
在您使用的 MimeKit 版本中,MimeMessage.Attachments
是 IEnumerable<MimePart>
,但是 message/rfc822 部分由 MessagePart
表示,它不包含 class MimePart
,它 subclass 是 MimeEntity
(这是 MimePart
的基础 class)。
在较新的版本中,MimeMessage.Attachments
改为 IEnumerable<MimeEntity>
,因此将包括您的 message/rfc822 附件。
您可以通过使用 BodyParts
属性 而不是 Attachments
属性.