Gmail doesn't display some of embedded images

让人想犯罪 __ 提交于 2019-12-11 14:50:12

问题


I'm creating a service which sends emails with a lot of embedded images. And often these images are being randomly lost in gmail web client using Chrome and other browsers (see the attached screenshot). I'm sure that the images are send correctly. The images are attached to email and the missed images could be successfully downloaded using Chrome context menu. If I press ctrl+F5 the images will be shown (or other images disapear). Also these emails are being displayed fine in Thunderbird or MS Outlook.

Here is a screnshot from my Chrome:

Please advice how I could change email body (maybe add some headers etc.) to woraround this issue!

Usage of external images (like <img src="http://mydomain/img.png">) is not preferable. Only embedded images like <img src="cid:img.png">

The emails are being sent through Amazon Web Services mail sender. Also I'm using javamail to send the images.

Here is a sample email text:

Return-Path: <0000014117bed1a2-aad7fbff-afdd-43ea-a658-825a817e9903-000000@amazonses.com>
Received: from a8-83.smtp-out.amazonses.com (a8-83.smtp-out.amazonses.com. [54.240.8.83])
        by mx.google.com with ESMTP id nd18si8517742qeb.113.1969.12.31.16.00.00;
        Fri, 13 Sep 2013 08:36:38 -0700 (PDT)
Received-SPF: pass (google.com: domain of 0000014117bed1a2-aad7fbff-afdd-43ea-a658-825a817e9903-000000@amazonses.com designates 54.240.8.83 as permitted sender) client-ip=54.240.8.83;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of 0000014117bed1a2-aad7fbff-afdd-43ea-a658-825a817e9903-000000@amazonses.com designates 54.240.8.83 as permitted sender) smtp.mail=0000014117bed1a2-aad7fbff-afdd-43ea-a658-825a817e9903-000000@amazonses.com
Return-Path: 0000014117bed1a2-aad7fbff-afdd-43ea-a658-825a817e9903-000000@amazonses.com
From: <my service email here>
Sender: <my service email here>
To: <my receiver email here>
Message-ID: <0000014117bed1a2-aad7fbff-afdd-43ea-a658-825a817e9903-000000@email.amazonses.com>
Subject: =?UTF-8?Q?RedHelper_-_=D0=BF?=
 =?UTF-8?Q?=D0=BB=D0=B0=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9?=
 =?UTF-8?Q?_=D0=BE=D1=82=D1=87=D1=91=D1=82_?=
 =?UTF-8?Q?(c_06.09.2013_=D0=BF=D0=BE_12.09.2013)?=
MIME-Version: 1.0
Content-Type: multipart/related; 
    boundary="----=_Part_0_68348157.1379082638282"
Date: Fri, 13 Sep 2013 14:34:43 +0000
X-SES-Outgoing: 2013.09.13-54.240.8.83

------=_Part_0_68348157.1379082638282
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

<table width=3D"750" align=3D"center" bgcolor=3D"#f2f4e6" cellpadding=3D"0"=
 cellspacing=3D"0"
=09   style=3D"
=09   =09=09border-collapse: collapse;
=09   =09=09font-family: arial, sans-serif;
=09   =09=09color: #374550;
=09   =09=09font-size: 14px;
=09   =09=09">
=09<tr>
=09=09<td>
=09=09=09<img src=3D"cid:client_report_header.png" alt=3D"RedHelper - =D0=
=BF=D0=BB=D0=B0=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9 =D0=BE=D1=82=D1=87=D1=91=D1=
=82" width=3D"750" height=3D"124"/>

...........................
The rest of email body
...........................

------=_Part_0_68348157.1379082638282
Content-Type: image/png; name=client_report_header.png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=client_report_header.png
Content-ID: <client_report_header.png>
X-Attachment-Id: client_report_header.png

...........................
base64 encoded image
...........................
...........................
then a lot of other images
...........................

Please help me to solve this problem, I'am at an impasse with it :(

Update:

I've explored the requests that browser makes for the embedded images and found that gmail attachment service sometimes returns wrong response headers (e.g. with text/html type insted of image/png) and then the images are not being displayed.

Here is an example of "good" response headers (copied from Chrome developer tools):

Request URL:https://mail-attachment.googleusercontent.com/attachment/u/0/?ui=2&ik=da16498049&view=att&th=141543ec8afd95ce&attid=0.49&disp=emb&zw&atsh=1&saduie=AG9B_P_B99tk3pnLfQHlDF_gPQKM&sadet=1380097953720&sads=D0OzbnmhqzBZ6htOe0o3RTWuwvw
Request Method:GET
Status Code:200 OK

Request Headers
:host:mail-attachment.googleusercontent.com
:method:GET
:path:/attachment/u/0/?ui=2&ik=da16498049&view=att&th=141543ec8afd95ce&attid=0.49&disp=emb&zw&atsh=1&saduie=AG9B_P_B99tk3pnLfQHlDF_gPQKM&sadet=1380097953720&sads=D0OzbnmhqzBZ6htOe0o3RTWuwvw
:scheme:https
:version:HTTP/1.1
accept:image/webp,*/*;q=0.8
accept-encoding:gzip,deflate,sdch
accept-language:en-US,en;q=0.8,ru;q=0.6
cookie:S=gmail=QQ8uQOaAEhQ4x5TFVYcQhg
referer:https://mail.google.com/mail/u/0/
user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
x-chrome-variations:CK61yQEIhrbJAQiqtskBCMS2yQEIt4XKAQjxhsoB

Response Headers
access-control-allow-credentials:true
alternate-protocol:443:quic
cache-control:private, max-age=86400
content-disposition:attachment; filename="visitors_capture_pic.png"
content-length:4336
content-type:image/png
date:Wed, 25 Sep 2013 08:32:14 GMT
server:GSE
status:200 OK
version:HTTP/1.1
x-content-type-options:nosniff
x-xss-protection:0

And here is an example of "bad" response headers:

Request URL:https://mail-attachment.googleusercontent.com/attachment/u/0/?ui=2&ik=da16498049&view=att&th=141543ec8afd95ce&attid=0.5&disp=emb&zw&atsh=1&saduie=AG9B_P_B99tk3pnLfQHlDF_gPQKM&sadet=1380097948083&sads=37LZqateabeXb45jYSk9ooGybwI
Request Method:GET
Status Code:200 OK

Request Headers
:host:mail-attachment.googleusercontent.com
:method:GET
:path:/attachment/u/0/?ui=2&ik=da16498049&view=att&th=141543ec8afd95ce&attid=0.5&disp=emb&zw&atsh=1&saduie=AG9B_P_B99tk3pnLfQHlDF_gPQKM&sadet=1380097948083&sads=37LZqateabeXb45jYSk9ooGybwI
:scheme:https
:version:HTTP/1.1
accept:image/webp,*/*;q=0.8
accept-encoding:gzip,deflate,sdch
accept-language:en-US,en;q=0.8,ru;q=0.6
cookie:S=gmail=QQ8uQOaAEhQ4x5TFVYcQhg
referer:https://mail.google.com/mail/u/0/
user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
x-chrome-variations:CK61yQEIhrbJAQiqtskBCMS2yQEIt4XKAQjxhsoB

Response Headers
alternate-protocol:443:quic
cache-control:no-cache, no-store, max-age=0, must-revalidate
content-encoding:gzip
content-type:text/html; charset=UTF-8
date:Wed, 25 Sep 2013 08:32:09 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:GSE
status:200 OK
version:HTTP/1.1
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block

Then if I try to download a missing image in a separate browser page it gives me 3 "302 Moved Temporarily" requests and finally a "200 OK" which gives the image.

来源:https://stackoverflow.com/questions/18975951/gmail-doesnt-display-some-of-embedded-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!