Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an email with embedded images that is compatible with the most mail clients

We have created a system that allows embedding an image in an outgoing email.

Here is the original message our system creates. This example contains an image attachment and an embedded image.

Mime-Version: 1.0 From: ... To: ... CC:  Subject: test x-sender: ... x-mailer: ... Content-Type: multipart/mixed; boundary="-------------...A128803765634794"  ---------------...A128803765634794 Content-Type: multipart/related; boundary="-------------...B128803765634796"  ---------------...B128803765634796 Content-Type: text/html; charset="UTF-8"  <p style="margin: 0; padding: 0"><img src="cid:083.gif" alt="" /></p>  ---------------...B128803765634796 Content-type: image/gif; name="083.gif" Content-ID: <083.gif> X-Attachment-Id: 083.gif Content-Disposition: Embedded; filename="083.gif" Content-transfer-encoding: base64  ............................................................................ ............................................................................ ...................................................... ---------------PineappleCodeB128803765634796-- ---------------PineappleCodeA128803765634794 Content-type: image/gif; name="waiting.gif" Content-Disposition: Attachment; filename="waiting.gif" Content-transfer-encoding: base64  ............................................................................ ............................................................................ ...................................................... ---------------PineappleCodeA128803765634794-- 

Is there another header I should add or rule I should follow?

I noticed one thing... I would guess that it is part my issue and part Gmails. but at any rate I would like to make it stop happening

When the email is received into Gmail I get

Images are not displayed.
Display images below - Always display images from ...

The embedded image is then shown as an image attachment (just like my other image attachment)

I click Display Images Below and my image is shown in the body of the email but not removed from the Attachments section.

If I go back to my in box and back to the email it looks fine.

I do not see why it does that. It it not a linked image (from external URL) and it does not happen when sending embedded images from Gmail to Gmail. That is what makes me think I might be doing somthing wrong and I am afraid that it may affect other recipients.

like image 872
700 Software Avatar asked Oct 25 '10 20:10

700 Software


People also ask

What size should an embedded image be in an email?

In fact, most experts state that the optimal image width is 600 pixels. There isn't a specific email image height to respect. However, always keep in mind the size of your file and the length of your overall email. Header image size should be around 600px – 700 px wide and around 100px-200px for the height.

Does Gmail support embedded images?

The Gmail Compose window can contain natively-embedded images only if you insert them using the “Insert photo” feature using the Photos, Albums, or Upload tabs.

Should you embed image in email?

High-quality images can spice up your email campaign. They evoke emotions, provide valuable information, engage your recipients, and encourage them to take action. While you should include images in your emails, there's a catch to it: embedding them can take a lot of work, and we mean, a lot.


2 Answers

I've had success with exactly the same headers as you're using, with the following differences:

  • Embedded is not a valid value for the Content-Disposition header. attachment should be fine. inline should also be fine, though I've usually seen attachment for multipart/related embedded images.

  • The value of the Content-ID header is supposed to be in the same format as a message-id, which in turn looks very much like an email address. <083.gif@yourmailer> has a better chance of working with most mailers.

like image 116
dkarp Avatar answered Sep 30 '22 09:09

dkarp


I was having trouble loading inline images in Gmail and I found that I was mis-using the PEAR Mail_Mime library in PHP. As already noted, the Content-ID must be formatted like a message id. The PEAR Mail_Mime library will try to add a domainID to your Content-ID if one is not supplied. It will also attempt to regex replace these Content-ID's in the HTML body of the email to maintain the link. In my case, this step was failing which did end up breaking the link from the HTML tag to the MIME attachment. So it was perfectly correct for Gmail to refuse to display the image inline. It did display the image as an attachment however.

like image 21
Kim Anthony Groves Avatar answered Sep 30 '22 10:09

Kim Anthony Groves