Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionMailer email images broken in some clients

I'm using ActionMailer to send emails, and these emails include images. To include the images I'm using <%= image_tag('email-logo.png') %> and config.action_controller.asset_host in staging/production is set correctly.

These images appear fine in Outlook (I also tried it in a few temp email services, and they work there as well), but appear broken in Gmail, Apple Mail (desktop + iOS), and Mailbox app.

The encoding for the HTML version of the email is quoted-printable, is that correct?

When I inspect the raw email in Gmail, the markup for the image appears like:

  <img alt=3D"Site Logo" class=3D"logo" src=3D"//staging.mysite.come/ass=
ets/email-logo-98e7cf6a48a4f2186ab9de2dcdfaa4bf0.png" style=3D"width: 30=
px; display: inline; vertical-align: middle;" />

When I remove the = and load the URL in my browser it appears fine. Could the = be breaking it? Could it be the lack of protocol in the image URL?

Thanks for any help in advance!

like image 832
Jody Heavener Avatar asked Jul 03 '15 16:07

Jody Heavener


People also ask

Why are my images broken in Gmail?

You can even use a different image for each recipient. If images aren't correctly displayed in the emails sent (you can send you a test email to try), it means your Gmail draft is partially broken. In that case, best is to create a new draft, and re-insert your image in this new draft.

How do I view broken images in Gmail?

You can get this using Gmail's Show original feature: Open the message, then click on the three vertical dots just right of the upper Reply button then on Show Original.


1 Answers

There's nothing wrong with the =. It's a soft line break in quoted-printable encoding used to comply with the 76 chars line length, and it is removed and the two lines joined when the text is decoded. See the wikipedia page on Quoted-printable for more info.

I suspect Gmail is not being able to prefetch the image. Gmail tries to prefetch the image and then serve it from their secure proxy servers. See this official post for more info about that. To do so, the image needs to have a publicly accessible url. A similar thing might be happening with the other clients.

So two things might be happening here:

  • Gmail (and the other clients) does not support a protocol relative (or "schemaless") url (they might try http then https, but I don't know if they do that). To be safe I would use a full url.
  • The image is not publicly accessible, even when tried with http or https. You are using a staging env, perhaps it's protected with http basic auth? Also the .come as TLD in staging.mysite.come is strange, but I assume it was just a typo...
like image 151
nberger Avatar answered Oct 18 '22 12:10

nberger