简体   繁体   English

多部分/混合电子邮件附件未显示,但仅在Windows 10 Mail中显示

[英]Multipart/mixed email attachments not showing up, but only in Windows 10 Mail

Having a weird problem with emails I am sending out via Python email / smtplib . 我通过Python email / smtplib发送的电子邮件有一个奇怪的问题。

I am attempting to compose an email with: 我正在尝试撰写一封电子邮件:

  • Alternatives of plain-text and HTML message bodies 纯文本和HTML邮件正文的替代方法
  • An image embedded inline in the HTML body 嵌入在HTML正文中的图像
  • A separate non-inline attachment 单独的非内联附件

The MIME structure is setup like this: MIME结构设置如下:

multipart/mixed
    multipart/alternative
        text/plain
        multipart/related
            text/html
            image/png - inline
    application/pdf - attachment

This seems to work fine on every mail client I've tested {BlueMail on Android, iOS mail client, Roundcube} except for the Windows 10 mail client. 这似乎在我测试的每个邮件客户端上运行良好{在Android上运行BlueMail,iOS邮件客户端,Roundcube}, 除了 Windows 10邮件客户端。 For some reason, the Windows 10 built-in mail client seems to show the inline image just fine, but shows no trace of the other attachment. 出于某种原因,Windows 10内置邮件客户端似乎显示内联图像就好了,但没有显示其他附件的痕迹。

The limited information I have been able to find on the internet points to this being a bug with the Windows 10 mail client, but I have personally received other emails in this client with both inline and attached attachments, which are displayed just fine - so there obviously is some sort of workaround / alternative message structure that works. 我在互联网上找到的有限信息表明这是Windows 10邮件客户端的一个错误,但我个人收到了这个客户端的其他电子邮件,包括内联和附加的附件,显示得很好 - 所以那里显然是某种解决方法/替代消息结构有效。

My question is thus: How can I format this message differently so that it will show up properly in all relevant mail clients? 我的问题是: 我如何以不同方式格式化此消息,以便它能在所有相关邮件客户端中正确显示?

I am composing the email like this, in Python: 我在Python中编写这样的电子邮件:

message = MIMEMultipart("mixed")
message["From"] = ...
.
.
.
bodyText = "..."
bodyHTML = "..."
mailFrom = "..."
targetEmail = "..."
imageContent = ...

messageBody = MIMEMultipart("alternative")
messageBody.attach(MIMEText(bodyText, "plain"))

messageBodyHTML = MIMEMultipart("related")
messageBodyHTML.attach(MIMEText(bodyHTML, "html"))
messageImage = MIMEImage(imageContent)
messageImage.add_header("Content-Disposition", 'inline; filename="..."')
messageImage.add_header("Content-ID", "<id used in html body>")
messageBodyHTML.attach(messageImage)

messageBody.attach(messageBodyHTML)

message.attach(messageBody)


attachment = MIMEApplication(fileContent, Name=fileName)
attachment.add_header("Content-Disposition", 'attachment; filename="..."')
message.attach(attachment)


self.smtplibSession.sendmail(mailSource, targetEmail, message.as_string())

Update: Here's the message data from Windows 10 mail (as output via the "save" feature - there's no way to view the original message raw data that I can find...) 更新:这是来自Windows 10邮件的消息数据(通过“保存”功能输出 - 无法查看我可以找到的原始消息原始数据...)

MIME-Version: 1.0
Date: Thu, 30 May 2019 17:45:28 +0200
From: xxxxx <xxxxx>
Subject: xxxxx
Thread-Topic: xxxxx
To: "xxxxx" <xxxxx>
Content-Type: multipart/related;
    boundary="_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_"

--_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<center><img src=3D"cid:embedded-image" alt=...

--_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_
Content-Type: image/png; name="embedded-image.png"
Content-ID: <embedded-image>
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="embedded-image.png"

iVBORw0KGgoAAAAN...

--_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_--

I'm not sure if this is a result of saving the email from the app, or this is what the app is actually storing, but it seems that the Windows 10 Mail app is cutting out everything outside the multipart/related stanza - that is, it's only taking the chosen alternative and not storing anything else. 我不确定这是否是从应用程序保存电子邮件的结果,或者这是应用程序实际存储的内容,但似乎Windows 10 Mail应用程序正在删除multipart/related节之外的所有内容 - 这是,它只采取选择的alternative而不是存储任何其他东西。

For comparison, I've found and exported an email that displayed properly, with an image, html, and attachment, but the format seems to be a lot simpler - that email consisted only of a multipart/mixed layer with text/html and an application/pdf attachment. 为了比较,我发现并导出了一个正确显示的电子邮件,带有图像,html和附件,但格式似乎更简单 - 该电子邮件仅包含带有text/htmlmultipart/mixed层和application/pdf附件。 That email used an external image referenced in the HTML, instead of embedding it in the message - I would like to avoid hosting the images in each email externally. 该电子邮件使用HTML中引用的外部图像,而不是将其嵌入到邮件中 - 我希望避免在外部托管每封电子邮件中的图像。

Unlike you, there was no problem with the attachment file, instead I've had problems in displaying inline images ( Windows 10 Mail 16005.11629.20174.0 ). 与您不同,附件文件没有问题,而是在显示内嵌图像时出现问题( Windows 10 Mail 16005.11629.20174.0 )。

Unfortunately, handling non-standard approaches in MIME messages correctly is a feature that is expected to have good email clients. 遗憾的是,正确处理MIME邮件中的非标准方法是一项预计具有良好电子邮件客户端的功能。 Apparently Windows 10 Mail is not as "good" yet. 显然Windows 10 Mail还不是那么“好”。

The structure I recommend you to use is: 我建议你使用的结构是:

multipart/mixed
├─── multipart/related
│   ├─── multipart/alternative
│   │   ├─── text/plain
│   │   └─── text/html
│   └─── image/png - inline image
└─── application/pdf - attachment

I've had no problems with this structure in the following clients. 我在以下客户端中对此结构没有任何问题。

  • Windows 10 Mail Windows 10 Mail
  • Gmail Web & Android Gmail网络和Android
  • Outlook Web & Android & Windows Desktop Outlook Web和Android&Windows桌面
  • Blue Mail Android Blue Mail Android
  • Roundcube Web Roundcube Web
  • MailEnable Web MailEnable Web

So, give the following code a try to see if it works for you. 因此,请尝试以下代码,看看它是否适合您。

message = MIMEMultipart("mixed")
message["From"] = ...
.
.
.
bodyText = "..."
bodyHTML = "..."
mailFrom = "..."
targetEmail = "..."
imageContent = ...
fileContent = ...

relatedBody = MIMEMultipart("related")

messageBody = MIMEMultipart("alternative")
messageBody.attach(MIMEText(bodyText, "plain"))
messageBody.attach(MIMEText(bodyHTML, "html"))

relatedBody.attach(messageBody)

messageImage = MIMEImage(imageContent)
messageImage.add_header("Content-Disposition", 'inline; filename="..."')
messageImage.add_header("Content-ID", "<id used in html body>")

relatedBody.attach(messageImage)

message.attach(relatedBody)

attachment = MIMEApplication(fileContent)
attachment.add_header("Content-Disposition", 'attachment; filename="..."')

message.attach(attachment)

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

相关问题 Python发送的MIME电子邮件附件未显示在mail.live中 - Python-sent MIME email attachments not showing up in mail.live Python 发送的 MIME email 附件未显示在某些客户端中 - Python-sent MIME email attachments not showing up in some clients send_mail显然正在发送电子邮件,但收件箱中未显示任何电子邮件 - send_mail is clearly sending email but no email is showing up in inbox [Python]为什么 email pdf 附件不显示在 Outlook/Thunderbird 上,而在 Gmail 上显示? (从 Python 环境发送) - [Python]Why are email pdf attachments not showing up on Outlook/Thunderbird, while they do on Gmail? (Sent from a Python environment) 如何提取多部分 email 的正文并使用 python IMAP 保存附件? - How to extract the body of an multipart email and save the attachments using python IMAP? 在 anaconda 中安装 OpenCV 未显示在 Windows 10 的 VS Code 中 - Installation of OpenCV in anaconda not showing up in VS Code in Windows 10 Windows 10 Python 3.6中没有显示名为&#39;tensorflow&#39;的模块错误 - No module named 'tensorflow' error showing up in Windows 10 Python 3.6 python smtplib multipart email 主体未在 iPhone 上显示 - python smtplib multipart email body not showing on iphone Python 仅保存电子邮件正文中的附件 - Python is saving only the attachments from e-mail body 扭曲加工多部分/混合 - Processing Multipart/mixed on Twisted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM