HTML-Email with inline attachments and non-inline attachments

前端 未结 1 515
臣服心动
臣服心动 2020-12-04 15:55

What is the correct way to create a HTML-Email with inline attachments and non-inline attachments?

In addition please tell me what Content-Type to use with only inli

相关标签:
1条回答
  • 2020-12-04 16:47

    Images

    Yes, it is correct approach to use multipart/related content type. Here is an example (please note 'Content-Type' and 'Content-Disposition' values):

    enter image description here

    Example source and detailed info

    Here are samples you've requested:

    1. Email with inline only attachments
    2. Email with non-inline only attachments
    3. Email with inline and non-inline attachments

    Sample 1: inline only

    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--
    

    Sample 2: only attachments

    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--
    

    Sample 3: inline and attachments

    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--
    

    Quick summary

    1. Inline only attachments: use multipart/related
    2. Non-inline only attachments: use multipart/mixed
    3. Inline and non-inline attachments use multipart/mixed and multipart/related

    Update

    Here is a very interesting article: Using Images in HTML Email

    0 讨论(0)
提交回复
热议问题