MimeKit 看不到 html 附件

发布于 2025-01-18 06:53:05 字数 715 浏览 5 评论 0原文

我正在使用Mimekit从邮件中下载.pdf附件。今天,我收到了一个带有两个附件的邮件,第一个“ part_1.html”和第二个“ sample.pdf”。这是我第一次获得.html附件(这是一个邮件正文,也是附件,IDK),而我的代码在附件中返回null。我不明白为什么在代码中,邮件没有附件。如果我再次发送此邮件,但没有此HTML可以将所有思想都正确地工作。

代码正在Attactemnts中查找.pdf,并在“ ISANYPDF”上设置为true,接下来是我的代码下载附件,但现在列表为null。 代码:

var Email = client.Inbox.GetMessage(MailId);
            ListOfAttachments = Email.Attachments.Where(x => x.IsAttachment).ToList();
            IsAnyPDF = ListOfAttachments.Any(x => x.ContentDisposition.FileName?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? x.ContentType.Name?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? false);

是否有可能在MailKit.Attachments中以某种方式避免使用此附件?

I'm using MimeKit to download .PDF attachment from mails. Today I got a mail with two attachments, first "part_1.html" and second "sample.pdf". This is first time when I got .HTML attachment (this a mail body but also in attachment, idk) and my code return null in attachments. I can't understand why in code, mail dosen't have attachments. If I send this mail again but without this html somethink everythink works properly.

Code is looking in attachemnts for .PDF, and set true on "IsAnyPdf", next my code download attachment from list but now list is null.
Code:

var Email = client.Inbox.GetMessage(MailId);
            ListOfAttachments = Email.Attachments.Where(x => x.IsAttachment).ToList();
            IsAnyPDF = ListOfAttachments.Any(x => x.ContentDisposition.FileName?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? x.ContentType.Name?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? false);

Is it possible to somehow avoid this attachment in MailKit.Attachments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2025-01-25 06:53:05

这是不必要的:

ListOfAttachments = Email.Attachments.Where(x => x.IsAttachment).ToList();

Mimemessage。编号已经只包含Isattachment是真实的部分,因此这是浪费。

至于为什么您的代码没有找到PDF“附件”,问题是100%保证的是PDF“附件”不是“附件”,而是将其添加到消息中为“ inline”。

所以...这样做:

var Email = client.Inbox.GetMessage(MailId);
IsAnyPDF = Email.BodyParts.OfType<MimePart>().Any(x => x.ContentDisposition.FileName?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? x.ContentType.Name?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? false);

This is unnecessary:

ListOfAttachments = Email.Attachments.Where(x => x.IsAttachment).ToList();

MimeMessage.Attachments already only includes parts where IsAttachment is true, so it's a waste.

As far as why your code isn't finding the pdf "attachment" goes, the problem is 100% guaranteed to be that the pdf "attachment" isn't an "attachment", but rather added to the message as "inline".

So... do this:

var Email = client.Inbox.GetMessage(MailId);
IsAnyPDF = Email.BodyParts.OfType<MimePart>().Any(x => x.ContentDisposition.FileName?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? x.ContentType.Name?.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase) ?? false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文