Home > Blockchain >  Why is my MIME multipart email inline image showing up as an attachment called ATT00001?
Why is my MIME multipart email inline image showing up as an attachment called ATT00001?

Time:01-13

I'm trying to create a MIME email from scratch with text and html alternatives and an inline image in the html. I get the email, and I see the html alternative in my mail client, but the inline image I expect to see is coming in as an attachment called ATT00001

Here's what it looks like prior to base64 encoding:

From: Me <[email protected]> 
To: Me <[email protected]> 
Subject: test message 
MIME-Version: 1.0
Content-Type: multipart/related; boundary="_BOUNDRY_RELATED_"; type="multipart/alternative"

--_BOUNDRY_RELATED_
Content-Type: multipart/alternative; boundary="_BOUNDRY_ALT_"

--_BOUNDRY_ALT_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This is text

--_BOUNDRY_ALT_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<body>
<h3>This is HTML</h3>
<img src="cid:[email protected]"/>
</body>
</html>

--_BOUNDRY_ALT_--
--_BOUNDRY_RELATED_

Content-Type: image/jpeg; name="myimage.jpg"
Content-Description: myimage.jpg
Content-Disposition: inline; filename="myimage.jpg"
Content-ID: <[email protected]>
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQEAYABgAAD/7QEwUGhvdG9zaG9 ...

--_BOUNDRY_RELATED_--

CodePudding user response:

On the MIME part for the image, you need to remove the blank line that is between its opening --_BOUNDRY_RELATED_ boundary and its Content-Type header:

       --_BOUNDRY_ALT_--
       --_BOUNDRY_RELATED_
here >  
       Content-Type: image/jpeg; name="myimage.jpg"
       Content-Description: myimage.jpg
       Content-Disposition: inline; filename="myimage.jpg"
       Content-ID: <[email protected]>
       Content-Transfer-Encoding: base64

       ...

       --_BOUNDRY_RELATED_--

Inside a MIME part, its headers and body are separated by a <CRLF><CRLF> sequence.

Because of that extra line, none of your image's headers will get processed by the email reader, as they will be interpreted as body data instead, so the reader won't know what kind of attachment it is, or what its name is. Hence the default generic naming you are seeing.

None of your other MIME parts have that extra line above their headers.

CodePudding user response:

I think my problem was the usage of quoted-printable transfer encoding. I ripped it off, to select the default, and it worked. I basically ended up with ...

From: Me <[email protected]> 
To: Me <[email protected]> 
Subject: test message 
MIME-Version: 1.0
Content-Type: multipart/related; boundary="_BOUNDRY_RELATED_"

--_BOUNDRY_RELATED_
Content-Type: multipart/alternative; boundary="_BOUNDRY_ALT_"

--_BOUNDRY_ALT_
Content-Type: text/plain

This is text

--_BOUNDRY_ALT_
Content-Type: text/html

<html>
  <head>
    <meta http-equiv="content-type" content="text/html;">
  </head>
  <body>
    <h3>This is HTML</h3>
    <img src="cid:[email protected]" alt="myimage.jpg">
  </body>
</html>

--_BOUNDRY_ALT_--

--_BOUNDRY_RELATED_
Content-Type: image/jpeg; name="myimage.jpg"
Content-Description: myimage.jpg
Content-Disposition: inline; filename="myimage.jpg"
Content-ID: <[email protected]>
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQEAYABgAAD/7QEwUGhvdG9zaG9 ...

--_BOUNDRY_RELATED_--

It would also appear that Exchange Server pretty much rewrites the whole thing as it passes through, but it does end up working.

  • Related