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

带有内联附件和非内联附件的HTML-Email,第1张

概述使用内联附件和非内联附件创建HTML电子邮件的正确方法是什么? 另外,请告诉我仅使用内联附件和仅使用非内联附件的内容类型. 直到现在我这样做: MIME-Version: 1.0[some more headers]Content-type: multipart/mixed; boundary="myboundary"--myboundaryContent-Type: text/html 使用内联附件和非内联附件创建HTML电子邮件的正确方法是什么?

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

直到现在我这样做:

MIME-Version: 1.0[some more @R_403_5548@s]Content-type: multipart/mixed; boundary="myboundary"--myboundaryContent-Type: text/HTML; charset=iso-8859-15Content-transfer-encoding: 7bit[HTML with img cID:my_image]--myboundaryContent-Type: image/png; name="my_image.png"Content-transfer-encoding: base64Content-ID: <my_image>Content-disposition: inline; filename="my_image.png"[base64 image data]--myboundaryContent-type:application/pdf;     name="my_pdf.pdf"Content-length:1150Content-transfer-encoding: base64Content-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 onlyTo: Renat GilmanovContent-Type: multipart/related; boundary=089e0149bb0ea4e55c051712afb5--089e0149bb0ea4e55c051712afb5Content-Type: text/HTML; charset=UTF-8Content-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>--089e0149bb0ea4e55c051712afb5Content-Type: image/png; name="test-01.png"Content-disposition: inline; filename="test-01.png"Content-transfer-encoding: base64Content-ID: <ii_ia6yo3z92_14d962f8450cc6f1>X-Attachment-ID: ii_ia6yo3z92_14d962f8450cc6f1iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB...QCDLAIEsAwSyDBDIMkAgywCblamesgwQyDJAimsAgSwDBliMEMgyQCDLAIEsAwSyDBDIMkAg6wK+4gU280YtuwAAAABJRU5ErkJggg==--089e0149bb0ea4e55c051712afb5--

示例2:仅附件

Subject: Test 02: only attachmentsTo: Renat Gilmanov Content-Type: multipart/mixed; boundary=047d7b41cc5c82ae5d051712c40c--047d7b41cc5c82ae5d051712c40cContent-Type: text/plain; charset=UTF-8Lorem ipsum dolor sit amet,consectetur adipiscing elit. Pellentesqueodio urna,dignissim in magna. Vivamus risusjusto,laoreet eget erat. Sed pretium a urnaID pulvinar.Cras eu velit ac purus feugiat imperdIEt nec sit amet ipsum. Praesentgravida lobortis justo,nec tristique velit sagittis finibus.Suspendisse porta ante ID diam varius,in cursus ante luctus. Aenean amollis mi. Pellentesque accumsan lacus sed erat vulputate,et sempertellus condimentum.Best regards--047d7b41cc5c82ae5d051712c40cContent-Type: image/png; name="test-02.png"Content-disposition: attachment; filename="test-02.png"Content-transfer-encoding: base64X-Attachment-ID: f_ia6yvl4b0iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB...gECWAQJZBghkGSCQZYBAlgECWQYIZBkgkGWAQJYBAlkGCGQZIJBlgECWAQJZBghkGSCQZYBA1gWVywTWDU1tpwAAAABJRU5ErkJggg==--047d7b41cc5c82ae5d051712c40c--

示例3:内联和附件

Subject: Test 03: inline and attachmentsTo: Renat GilmanovContent-Type: multipart/mixed; boundary=001a11c24d809f1525051712cc78--001a11c24d809f1525051712cc78Content-Type: multipart/related; boundary=001a11c24d809f1523051712cc77--001a11c24d809f1523051712cc77Content-Type: text/HTML; charset=UTF-8Content-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>--001a11c24d809f1523051712cc77Content-Type: image/png; name="test-01.png"Content-disposition: inline; filename="test-01.png"Content-transfer-encoding: base64Content-ID: <ii_ia6yyemg0_14d9636d8ac7a587>X-Attachment-ID: ii_ia6yyemg0_14d9636d8ac7a587iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB...QCDLAIEsAwSyDBDIMkAgywCblamesgwQyDJAimsAgSwDBliMEMgyQCDLAIEsAwSyDBDIMkAg6wK+4gU280YtuwAAAABJRU5ErkJggg==--001a11c24d809f1523051712cc77----001a11c24d809f1525051712cc78Content-Type: image/png; name="test-02.png"Content-disposition: attachment; filename="test-02.png"Content-transfer-encoding: base64X-Attachment-ID: f_ia6yymei1iVBORw0KGgoAAAANSUhEUgAAAUAAAADaCAYAAADXGps7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALewAAC3sBSRnwgAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALnSURB...gECWAQJZBghkGSCQZYBAlgECWQYIZBkgkGWAQJYBAlkGCGQZIJBlgECWAQJZBghkGSCQZYBA1gWVywTWDU1tpwAAAABJRU5ErkJggg==--001a11c24d809f1525051712cc78--

快速摘要

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

更新

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

总结

以上是内存溢出为你收集整理的带有内联附件和非内联附件的HTML-Email全部内容,希望文章能够帮你解决带有内联附件和非内联附件的HTML-Email所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1107380.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存