简体   繁体   English

使用Mailkit丢失附件

[英]Missing attachments using Mailkit

When I receive a mail with attahcment(s) from Exchange via IMAP protocol using MailKit, it's missing the attachment. 当我使用MailKit通过IMAP协议收到来自Exchange的邮件时,它缺少附件。 When I do: 当我做:

string.Format("Mail has {0} attachments", mime.Attachments.Count())

It report "0", even tho that the mail itself contain a attachment (I see the attachment if I open it in Outlook client), and when I activate the IMAP protocol logging, it's clearly that it contains an attachment: 它报告“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:
...

Funny thing is the "S: X-MS-Has-Attach:" header in the attachment part, within the same package from server. 有趣的是附件部分中的“S:X-MS-Has-Attach:”标题,位于服务器的同一个包中。

Is this a known issue, and how do I fix it so I won't miss the attachments in these cases? 这是一个已知的问题,我该如何修复它以便在这些情况下我不会错过附件? It only seems to happen on some mails and occur randomly. 它似乎只发生在一些邮件上并随机发生。

Using: MailKit 1.0.14.0 MimeKit 1.0.13.0 使用:MailKit 1.0.14.0 MimeKit 1.0.13.0

I discovered that there are new update, but I won't really update if this won't solve the issue anyway. 我发现有新的更新,但如果不能解决问题,我不会真正更新。

In the version of MimeKit that you are using, MimeMessage.Attachments is IEnumerable<MimePart> , but a message/rfc822 part is represented by a MessagePart which does not subclass MimePart , it subclasses MimeEntity (which is the base class for MimePart ). 在MimeKit的版本所使用, MimeMessage.AttachmentsIEnumerable<MimePart>但是一个消息/ RFC822部分由a表示MessagePart不继承MimePart ,它的子类MimeEntity (这是基类MimePart )。

In newer versions, MimeMessage.Attachments is IEnumerable<MimeEntity> instead, and so will include your message/rfc822 attachment. 在较新的版本中, MimeMessage.AttachmentsIEnumerable<MimeEntity> ,因此将包含您的消息/ rfc822附件。

You can work around this in your version of MimeKit by using the BodyParts property instead of the Attachments property. 您可以使用BodyParts属性而不是Attachments属性在您的MimeKit版本中解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM