Search code examples
amazon-web-servicesemailmimeamazon-ses

Embedding attached data in MIME, to the HTML portion of the email. Not linking to the attached file


I have generated this MIME data, that is sent through aws-ses. Here in the entire MIME data

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 alt="Embedded Image" 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--

I receive the email, but the image isn't embedding into the html part of the MIME The img tag is linked to the attached file

HTML CODE

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

MIME attachment

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

iVBORw0KGgoAAAANS...
--T4nu9J8b--

RESULTING EMAIL

enter image description here


Solution

  • The image attachment section needs Content-ID

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

    Note: Content-ID name should be put in an angular bracket, as given

    Embed it into tag using same Content-ID (without the angular bracket)

    <img alt="Embedded Image" src="cid:idname"/>
    

    This should allow the attach image to be displayed into the html!

    Complete resource: http://www.faqs.org/rfcs/rfc2387.html

    Question similar to Embedding attached images in HTML emails But I couldn't find an accurate answer. I'll post the same there too.