1

I am trying to generate an email text with an image inserted in it. I understand I should use the syntax <img src="cid:image-id" /> and add the image as attachment. I tried to do that and the result is the following :

--===============6239034322813840804==
Content-Type: multipart/alternative;
 boundary="===============6051774682785554910=="
MIME-Version: 1.0

--===============6051774682785554910==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

my email in base64 with text only

--===============6051774682785554910==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

my email in base64 with html
...
<img src="cid:my-image.png" alt="My Image">
...

--===============6051774682785554910==--
--===============6239034322813840804==
MIME-Version: 1.0
Content-Type: image/png; name="badge-img.png"
Content-Disposition: inline; filename="badge-img.png"
Content-ID: <badge-img.png>
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
...

When sent, the image is in attachment (can open it, valid image). But in the displayed email content, I only see the alt text "My Image", not the image.

Any idea why ?

Martin Trigaux
  • 5,311
  • 9
  • 45
  • 58

2 Answers2

0

What's the language you using? In C# you need try something like that:

sending mail along with embedded image using asp.net

or

Attaching Image in the body of mail in C#

Community
  • 1
  • 1
monteirobrena
  • 2,562
  • 1
  • 33
  • 45
0

Ok I think I found the problem. I have to use multipart/related content type and change the structure. I have currently something like this

<email>
    <part1 content-type=multipart/alternative>
        <subpart1>plain text</subpart1>
        <subpart2>html text</subpart2>
    </part1>
    <part2>
        attachments
    </part2>
</email>

and should have something like

<email>
    <part content-type=multipart/alternative>
        <subpart1>plain text</subpart1>
        <subpart2 content-type=multipart/related>
            <subsubpart1>html text</subsubpart1>
            <subsubpart2>attachments</subsubpart2>
        </subpart2>
    </part>
</email>

I still have to change my code to adapt but it seems to be the problem.

Martin Trigaux
  • 5,311
  • 9
  • 45
  • 58