带有内联附件和非内联附件的HTML-Email

前端之家收集整理的这篇文章主要介绍了带有内联附件和非内联附件的HTML-Email前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用内联附件和非内联附件创建HTML电子邮件的正确方法是什么?

另外,请告诉我仅使用内联附件和仅使用非内联附件的内容类型.

直到现在我这样做:

MIME-Version: 1.0
[some more headers]
Content-type: multipart/mixed;
 boundary="myboundary"
--myboundary
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

[html with img cid:my_image]

--myboundary
Content-Type: image/png;
 name="my_image.png"
Content-Transfer-Encoding: base64
Content-ID: <my_image>
Content-Disposition: inline;
 filename="my_image.png"

[base64 image data]

--myboundary
Content-type:application/pdf;
     name="my_pdf.pdf"
Content-length:1150
Content-Transfer-Encoding: base64
Content-ID: <my_pdf.pdf>
Content-Disposition: attachment;
 filename="my_pdf.pdf"

[base64 pdf data]

--myboundary--

邮件看起来很好看.但是我注意到Thunderbird没有显示我的内嵌图像,而是显示了2个附件(我的图像和我的PDF).所以我做了一些调试,发现内联图像应该通过Content-Type:multipart / related来发送.

所以我改变了Content-Type:multipart / mixed to Content-Type:multipart / related,Thunderbird显示正确:图像以html和一个附件显示,显示PDF.

如果这是正确的解决方案我虽然看似有效,但我并不感到害羞.是否正确使用multipart / related(如果我有内联和非内联附件,如果我只有内联附件,以防万一我只有非内联附件)?

或者是使用一个类型边界相关的拆分内联附件和另一个类型混合边界以拆分非内联附件的正确方法

我希望你能为我提供样品

>仅使用内联附件的电子邮件
>使用非内联仅附件的电子邮件
>包含内联和非内联附件的电子邮件

解决方法

图片

是的,使用多部分/相关内容类型是正确的方法.以下是一个示例(请注意’Content-Type’和’Content-Disposition’值):

Example source and detailed info

以下是您要求的样本:

>仅使用内联附件的电子邮件
>使用非内联仅附件的电子邮件
>包含内联和非内联附件的电子邮件

示例1:仅内联

Subject: Test 01: inline only
To: Renat Gilmanov
Content-Type: multipart/related; boundary=089e0149bb0ea4e55c051712afb5

--089e0149bb0ea4e55c051712afb5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Lorem ipsum dolor sit amet,consectetur adipiscing elit. P=
ellentesque odio urna,bibendum eu ultricies in,dignissim in magna. Vivamu=
s risus justo,viverra sed dapibus eu,laoreet eget erat. Sed pretium a urn=
a id pulvinar.<br><br><img src=3D"cid:ii_ia6yo3z92_14d962f8450cc6f1" height=
=3D"218" width=3D"320"><br>=E2=80=8B<br>Cras eu velit ac purus feugiat impe=
rdiet nec sit amet ipsum. Praesent gravida lobortis justo,nec tristique ve=
lit sagittis finibus. Suspendisse porta ante id diam varius,in cursus ante=
 luctus. Aenean a mollis mi. Pellentesque accumsan lacus sed erat vulputate=,et semper tellus condimentum.<br><br>Best regards<br></div>

--089e0149bb0ea4e55c051712afb5
Content-Type: image/png; name="test-01.png"
Content-Disposition: inline; filename="test-01.png"
Content-Transfer-Encoding: base64
Content-ID: <ii_ia6yo3z92_14d962f8450cc6f1>
X-Attachment-Id: ii_ia6yo3z92_14d962f8450cc6f1

iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
AAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB
...
QCDLAIEsAwSyDBDIMkAgywCBLAMEsgwQyDJAIMsAgSwDBLIMEMgyQCDLAIEsAwSyDBDIMkAg6wK+
4gU280YtuwAAAABJRU5ErkJggg==
--089e0149bb0ea4e55c051712afb5--

示例2:仅附件

Subject: Test 02: only attachments
To: Renat Gilmanov 
Content-Type: multipart/mixed; boundary=047d7b41cc5c82ae5d051712c40c

--047d7b41cc5c82ae5d051712c40c
Content-Type: text/plain; charset=UTF-8

Lorem ipsum dolor sit amet,consectetur adipiscing elit. Pellentesque
odio urna,dignissim in magna. Vivamus risus
justo,laoreet eget erat. Sed pretium a urna
id pulvinar.

Cras eu velit ac purus feugiat imperdiet nec sit amet ipsum. Praesent
gravida lobortis justo,nec tristique velit sagittis finibus.
Suspendisse porta ante id diam varius,in cursus ante luctus. Aenean a
mollis mi. Pellentesque accumsan lacus sed erat vulputate,et semper
tellus condimentum.

Best regards

--047d7b41cc5c82ae5d051712c40c
Content-Type: image/png; name="test-02.png"
Content-Disposition: attachment; filename="test-02.png"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ia6yvl4b0

iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
AAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB
...
gECWAQJZBghkGSCQZYBAlgECWQYIZBkgkGWAQJYBAlkGCGQZIJBlgECWAQJZBghkGSCQZYBA1gWV
ywTWDU1tpwAAAABJRU5ErkJggg==
--047d7b41cc5c82ae5d051712c40c--

示例3:内联和附件

Subject: Test 03: inline and attachments
To: Renat Gilmanov
Content-Type: multipart/mixed; boundary=001a11c24d809f1525051712cc78

--001a11c24d809f1525051712cc78
Content-Type: multipart/related; boundary=001a11c24d809f1523051712cc77

--001a11c24d809f1523051712cc77
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Lorem ipsum dolor sit amet,laoreet eget erat. Sed pretium a urn=
a id pulvinar.<br><br><img src=3D"cid:ii_ia6yyemg0_14d9636d8ac7a587" height=
=3D"218" width=3D"320"><br>=E2=80=8B<br>Cras eu velit ac purus feugiat impe=
rdiet nec sit amet ipsum. Praesent gravida lobortis justo,et semper tellus condimentum.<br><br>Best regards</div>

--001a11c24d809f1523051712cc77
Content-Type: image/png; name="test-01.png"
Content-Disposition: inline; filename="test-01.png"
Content-Transfer-Encoding: base64
Content-ID: <ii_ia6yyemg0_14d9636d8ac7a587>
X-Attachment-Id: ii_ia6yyemg0_14d9636d8ac7a587

iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
AAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB
...
QCDLAIEsAwSyDBDIMkAgywCBLAMEsgwQyDJAIMsAgSwDBLIMEMgyQCDLAIEsAwSyDBDIMkAg6wK+
4gU280YtuwAAAABJRU5ErkJggg==
--001a11c24d809f1523051712cc77--
--001a11c24d809f1525051712cc78
Content-Type: image/png; name="test-02.png"
Content-Disposition: attachment; filename="test-02.png"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ia6yymei1

iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
AAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB
...
gECWAQJZBghkGSCQZYBAlgECWQYIZBkgkGWAQJYBAlkGCGQZIJBlgECWAQJZBghkGSCQZYBA1gWV
ywTWDU1tpwAAAABJRU5ErkJggg==
--001a11c24d809f1525051712cc78--

快速摘要

>仅内联附件:使用multipart / related
>非内联仅附件:使用multipart / mixed
>内联和非内联附件使用multipart / mixed和multipart / related

更新

这是一篇非常有趣的文章Using Images in HTML Email

原文链接:https://www.f2er.com/html/231976.html

猜你在找的HTML相关文章