将 MIME 中的附加数据嵌入到电子邮件的 HTML 部分。未链接到附件

Posted

技术标签:

【中文标题】将 MIME 中的附加数据嵌入到电子邮件的 HTML 部分。未链接到附件【英文标题】:Embedding attached data in MIME, to the HTML portion of the email. Not linking to the attached file 【发布时间】:2019-02-19 04:12:30 【问题描述】:

我已经生成了这个通过 aws-ses 发送的 MIME 数据。在整个 MIME 数据中

Content-Type: multipart/mixed;boundary=T4nu9J8b
From: <noreply@noreply.in>
To: <myemail@gmail.com>
Subject: Your Image

--T4nu9J8b
Content-Type: multipart/alternate;boundary=R5I0TJcF

--R5I0TJcF
Content-Type: text/html;charset=utf-8

<h1> Hi!!! </h1><p>Here is your progress report </p><br/> <img  src="cid:testimage.png"/>
--R5I0TJcF
Content-Type: text/plain;charset=utf-8

This is the plain text version of the message.
--R5I0TJcF--
--T4nu9J8b
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment ;filename="testimage.png"

iVBORw0KGgoAAAANS...
--T4nu9J8b--

我收到了电子邮件,但图像未嵌入 MIME 的 html 部分 img 标签链接到附件

HTML 代码

<img  src="cid:testimage.png"/>

MIME 附件

--T4nu9J8b Content-Type: image/png Content-Transfer-Encoding: base64 Content-Disposition: attachment ;filename="testimage.png"

iVBORw0KGgoAAAANS...
--T4nu9J8b--

结果电子邮件

【问题讨论】:

【参考方案1】:

图片附件部分需要Content-ID

--T4nu9J8b
Content-Type: image/png
Content-ID: <idname>
Content-Transfer-Encoding: base64
Content-Disposition: attachment ;filename="testimage.png"

iVBORw0KGgoAAAANS...
--T4nu9J8b--

注意:Content-ID 名称应放在尖括号中,如给定的那样

使用相同的 Content-ID 将其嵌入到标签中(不带尖括号)

<img  src="cid:idname"/>

这应该允许附加图像显示到 html 中!

完整资源:http://www.faqs.org/rfcs/rfc2387.html

类似的问题 Embedding attached images in HTML emails 但我找不到准确的答案。我也会在那里发布相同的内容。

【讨论】:

以上是关于将 MIME 中的附加数据嵌入到电子邮件的 HTML 部分。未链接到附件的主要内容,如果未能解决你的问题,请参考以下文章

将一些文件附加到 MIME 多部分电子邮件

使用 MIMEApplication 将 s3 文件附加到 smtplib lib 电子邮件

在电子邮件中嵌入图片

重新发送 MIME 电子邮件中的标头

如何将.gpx文件附加到使用Google Apps脚本发送的邮件中?

电子邮件中的 MIME 多部分