gpt4 book ai didi

email - 带有内联附件和非内联附件的 HTML 电子邮件

转载 作者:行者123 更新时间:2023-12-03 13:56:10 26 4
gpt4 key购买 nike

创建带有内联附件和非内联附件的 HTML 电子邮件的正确方法是什么?

另外,请告诉我仅使用内联附件和仅使用非内联附件的 Content-Type。

直到现在我这样做:

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/mixedContent-Type: multipart/related并且 Thunderbird 正确显示:图像以 html 和一个附件显示,显示 PDF。

我不确定这是否是正确的解决方案,尽管它似乎有效。使用 multipart/related 是否正确总是(如果我有内联和非内联附件,如果我只有内联附件,如果我只有非内联附件)?

还是使用一种与拆分内联附件相关的类型边界和另一种混合类型边界来拆分非内联附件的正确方法?

我希望你能给我一个 sample
  • 仅带有内联附件的电子邮件
  • 仅包含非内联附件的电子邮件
  • 带有内联和非内联附件的电子邮件
  • 最佳答案

    图片

    是的,使用 multipart/related 是正确的方法内容类型。这是一个示例(请注意“Content-Type”和“Content-Disposition”值):

    enter image description here

    Example source and detailed info

    以下是您要求的 sample :

  • 仅带有内联附件的电子邮件
  • 仅包含非内联附件的电子邮件
  • 带有内联和非内联附件的电子邮件

  • 示例 1:仅内联

    enter image description here
    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:仅附件

    enter image description here
    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, bibendum eu ultricies in, dignissim in magna. Vivamus risus
    justo, viverra sed dapibus eu, 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:内联和附件

    enter image description here
    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, 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_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, 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</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/mixedmultipart/related

  • 更新

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

    关于email - 带有内联附件和非内联附件的 HTML 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30351465/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com