14

Recently Google announced that Gmail will load external images using a proxy for safety purpose. This causing an issue for my application while displaying images in gmail.

Gmail image element inspection: https://ci5.googleusercontent.com/proxy/N4RZncgANd5glVi64ElKxecSE10SH6iAhu2VKOK3jJtgaRKBUsqwOn6iDwY49unvlD9Xi6cSZp0T4u1N_KHhBY-TxFaV8PvPNSMn4A=s0-d-e1-ft#http://localhost:8080/email/thread/1301/images/correct) no-repeat">올바른 답변

As per above HTML actual image url is prepended with a Google proxy URL stopping images to be displayed. If we remove this garbage URL, image starts to appear fine. Same issue not appears for Apple Mac Mails.

We have provided mailing feature using Java Mailing API. Please suggest.

Thanks, Divya Garg

Divya Garg
  • 325
  • 1
  • 2
  • 8

1 Answers1

18

The problem here is the URL you are using for your mailings. From the information provided, it appears to be:

http://localhost:8080/email/thread/1301/images/correct

This is a URL that refers to a file on your local computer. However, that URL - rather than the actual image - is being passed to Google's proxy to retrieve. Google has no way to access that URL from their proxy, and thus the image will not appear.

The solution is to ensure that the path you are using is one accessible outside of your local network; for example, by hosting the images on an externally-facing server.

Adrian Wragg
  • 7,311
  • 3
  • 26
  • 50
  • 13
    For developping purposes, you can use this Javascript in your debugger console (F12) to display this pictures : (function(){ while(img = document.evaluate('//img[contains(@src, \'googleusercontent.com\')]', document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){ var src = img.attributes.src.value; src = src.substr(src.indexOf('#')+1); img.attributes.src.value = src; } })(); – JBreton Mar 18 '14 at 16:36
  • 2
    For outlook.com: `(function(){ while(img = document.evaluate('//img[contains(@src, \'mail.live.com\')]', document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){ var src = img.attributes.src.value; src = src.substr(src.indexOf('url=')+4); img.attributes.src.value = decodeURIComponent(src); } })();` – bakkay Jun 22 '15 at 16:40
  • 1
    @JBreton it freezes my pc – Victor Bredihin Jul 14 '20 at 20:14
  • @JBreton even if this used to work at some point, it seems now that it freezes my Firefox on Mac. – medonja Nov 25 '20 at 19:44
  • 5
    @VictorBredihin @medonja GMail design change broke my ol'lil'script. Here is an updated one : `(function(){ while(img = document.evaluate('//img[contains(@src, \'googleusercontent.com\')][contains(@src, \'#\')]', document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){ var src = img.attributes.src.value; src = src.substr(src.indexOf('#')+1); img.attributes.src.value = src; } })();` I added a criteria, src now needs to contain #. This prevents infinite loop. – JBreton Nov 26 '20 at 08:02
  • no, I used it not on localhost and also the same problem – Omar Nov 14 '22 at 17:36