8

HTML mail with an embedded image in gmail - with the following email body - just spits out the exact text. It does not show what's inside the "body" tags.

This is the content of the mail:

Content-Type: multipart/related;

boundary="bananarepublic12345"

This is a multipart message in MIME format.

--banana12345republic

Content-Type: text/html; charset=ISO-8859-1

Content-Transfer-Encoding: 7bit


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
      "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head> 
     <title>testing embedded image</title>
</head>
<body bgcolor="#000">
    <h1> Testing Embedded Image</h1>
    <img src="cid:mambo" alt="ALTERNATE TEXT" >
</body>
</html>

--bananarepublic12345

Content-Type: image/jpeg; name=big-image1.jpg

Content-Transfer-Encoding: base64

Content-ID: <mambo>

Content-Disposition: inline;

filename="big-image1.jpg"

/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ...//2Q%3D%3D

Where am I going wrong?

Thanks for any suggestion!

Guss
  • 30,470
  • 17
  • 104
  • 128
Van de Graff
  • 5,043
  • 13
  • 39
  • 41

1 Answers1

10

I've followed the instructions in question 4018709 and it worked nicely. To sum it up, you need the content-ids for the attachment to be formatted like message IDs (which in turn are formatted like email addresses - with an @ and a domain), and have the content ID value in the MIME part header of the image enclosed in angle brackets (like you already do).

So a sample email may look like this:

Date: Fri, 2 Dec 2011 06:57:55 GMT
Message-Id: <201112020657.pB26vttQ010231@geek.co.il>
Content-Type: multipart/related; boundary="=-blabla"; type="multipart/alternative"
From: Some sender <some-sender@geek.co.il>
To: Me <me@geek.co.il>
Subject: HTML content with embedded images
MIME-Version: 1.0

--=-blabla
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html><body>
<h1>Header</h1>
<h2><a href=3D"http://geek.co.il">link</a></h2>
<p>
<img border=3D"0" =
src=3D"cid:some.random.id@geek.co.il"/>
<p>
</body></html>

--=-blabla
Content-ID: <some.random.id@geek.co.il>
Content-Disposition: inline; filename="image.png"
Content-Type: image/png; name="image.png"
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAA9YAAAE2CAMAAACz7PorAAADAFBMVEUAAAC9...
Community
  • 1
  • 1
Guss
  • 30,470
  • 17
  • 104
  • 128
  • 1
    What does that "3D" do after the equals sign in your html? – doABarrelRoll721 Dec 30 '15 at 07:33
  • 3
    As you can see from the MIME headers of the HTML part, the HTML part is encoded using the "quoted-printable" encoding. Quoted-printable is a minimal text encoding that allow forcing a max line width by splitting long lines with a `=` character (and you can see this is used in line 5 of the HTML). As such, all `=` characters in the content (as well as any non-printable character) has to be "quoted" by writing them as `=`. so `border="0"` gets encoded into `border=3D"0"`. For more information, checkout RFC 2045. – Guss Dec 30 '15 at 08:44