Gmail's new image caching breaks image links in the newsletter

I have automatic emails that are sent after registration is completed on my site.

Until recently, they worked fine. Google’s new system now rewrites images and stores them in cache (presumably)

However, Google rewrites my links to images, completely breaking them, giving a 500 error and a broken link image.

Say my normal image url is:

http://www.mysite.com/images/pic1.jpg 

Google rewrites this:

 https://ci5.googleusercontent.com/proxy/vI79kajdUGm6Wk-fjyicDLjZbCB1w9NfkoZ-zQFOB2OpJ1ILmSvfvHmE56r72us5mIuIXCFiO3V8rgkZOjfhghTH0R07BbcQy5g=s0-d-e1-ft#http://www.mysite.com/images/pic1.jpg 

However, there is nothing in this URL.

Email showing image errors

So, something is wrong with the links that Google creates, or the images just don’t upload to googleusercontent, but I don’t know how to solve the problem.

I use PHP, phpmailer library and Ubuntu server on Amazon EC2, but I'm not sure if this is related to the problem.

+87
caching image rewrite gmail
Jan 03 '14 at 12:43 on
source share
14 answers

I think I figured out a problem with GoogleImageProxy.

This is due to the concept of CACHING. Suppose you recently deployed your php code on your server, but you forgot to upload the images. You tested once using your email. Your system has created an HTML email address. When this message arrives at the gmail server, GoogleImageProxy will try to extract and save the images from your site to its own proxy server. when receiving images GoogleImageProxy detected about 404 statuses against your missing images and 403 for some protected images. GoogleImagesProxy saved these statuses to its own proxy server.

Now, trying to open your email, you noticed about 404 statuses against your images. This is clear. You immediately realized that you forgot to upload some images, so you uploaded them to your server. and also you set some permissions for protected images.

You are all done. Now you are trying to run your php-email script again. As a result, you get another email in your Gmail or Hotmail inbox. You fixed all the problems with your images. Images should now display in your email content. but you still cannot see the images.

Or perhaps you forgot to clear your browser cache. Clear your browser’s cache and reload the gmail or hotmail page. But the result will be the same. Try to apply dozens of corrections / corrections and try to run php-email script thousands of times. But the result will be the same. No improvements.

REAL PROBLEM

What the hell is going on? Let me explain this to you. Go to your access log and try to find requests from GoogleImageProxy. You will be surprised to see that GoogleImageProxy will only have 2-3 or three requests depending on the number of different images used in your letter. GoogleImageProxy never tried to retrieve images. Even after fixing image problems by downloading missing images and setting permissions for protected images. What for? Clearing the browser cache is not affected. GoogleImageProxy will never receive fresh images even for your new email, since images are now cached in GoogleImageProxy with their latest status code and not cached in your own browser.

GoogleImageProxy has set its own expiration date for images. I think one month. therefore, a fresh copy of the images will now be selected after the expiration date. I mean in a month. You cannot force GoogleImageProxy to retrieve images. But it’s important that you display the images in your letter. What could be the solution?

DECISION

Below is the only way to get GoogleImageProxy to retrieve your images.

  • Rename your images to something else with the extensions png, jpg or gif only.
  • Do not use the query string in the image url, for example ?t=34343
  • Your image should include png, jpg or gif as an extension.
  • Your image url should display directly on your image.
  • If you need to use a proxy address for protected images, then your answer should contain the correct header, for example Content-Type: image/jpeg
  • The header of the file extension and content must match
  • The status code should be 200 instead of 403, 500, etc.

IMPORTANT NOTE

Try to repeat the whole process for each run php-email script. because every time GoogleImageProxy caches your images, you have to repeat the same process for every new attempt.

Hope this solves the problem for most people.

+71
Mar 21 '15 at 15:46
source share

Based on your example, it looks like you are using traditional extensions (.jpg, .png, .gif). Some people in this thread , describing the same problems you encountered, have stated that using these extensions solves the problem.

Other possible solutions:

+27
Jan 07 '14 at 22:44
source share

I had a similar problem, but it was caused by the length of the URL. When caching images from gmail, Google generates the following URL:

 https://ci4.googleusercontent.com/proxy/[hash]#[url]) 

The generated hash is based on the URL of the image, but the size will depend on the characters used. I conducted several tests with different URLs and found that the cached image will not load sequentially (400 / Invalid Request) if the hash exceeds 2076 characters (about 2048 bytes + meta not sure).

Again, the image URL can generate a hash that exceeds this number of characters by ~ 1000 special characters or more than 1500 simple characters. If the hash exceeds 2076 characters, the request does not work.

I understand this is an old post, but hopefully this will help other developers clear Google

+7
Mar 30 '17 at 21:04
source share

I know this is an old question, but the same thing happened to me. When I checked the access logs, this is what I found -

 www.example.ca 66.249.85.50 - - [10/Apr/2014:17:57:18 -0400] "GET /newsletters/Apr10_2014/cad/cad2.jpg HTTP/1.1" 403 457 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (via ggpht.com GoogleImageProxy)" 

You can see that my server blocked GOOGLEIMAGEPROXY , giving it a 403 Forbidden response. I decided to check my .htaccess and, of course, blocked the term PROXY . After deleting the term, the images are now displayed in Gmail. Hope this helps.

+6
May 01 '14 at 8:45
source share

HTTPS image points are stored in the cache. In some of our production environments, there is no problem proximating gmail images using HTTPS uri. I have seen gmail ignore your content if the SSL certificate is incorrect.

+3
May 16 '14 at 21:53
source share

I just tried after replacing the image (without changing the image name)

  • Open email in a new browser, it shows a new image

  • Ctrl + F5 (forced cache update) in Chrome (my default browser) also shows a new image

+3
Mar 15 '18 at 6:02
source share

Verify that the content type returned by the image file by your server is correct.

You can check this with Fiddler.

+1
Jan 12 '14 at 2:06
source share

In my case, the problem was the file size, it was 22 MB (I know, right?), And after we reduced the size, everything began to work like a charm.

Check the file size and if it is too large, compress it.

+1
Jun 08 '18 at 7:33
source share

Make sure Gmail requests your image on top of http , not https .

Suppose your regular image URL is:

 https://www.mysite.com/images/pic1.jpg 

So change to:

 http://www.mysite.com/images/pic1.jpg 

I have a strong feeling that google proxy is not caching https .

0
Apr 25 '14 at 19:28
source share

I have a perfect solution to this problem that worked for me, if you are using PHPMailer, you just need to add another option to PHPMailer to attach an image like this

$mail = new PHPMailer(); $mail->AddEmbeddedImage('../absolutepath/image/image.jpg', 'logoimg', '../absolutepath/image/image.jpg');

Here we indicated the absolute path to the image and assigned it a name called "logoimg", or whatever.

Now you can add this logo anywhere in your HTML body like this

$mail->Body = " <h1>Test of PHPMailer html body with image</h1> <p>This is a test picture: <img src=\"cid:logoimg\" /></p>"; $mail->send();

It's all.

0
Aug 10 '18 at 11:53
source share
 use .png or .jpg otherwise image will not render 

URL add car

0
Mar 23 '19 at 7:50
source share

I had this problem when I sent pictures. I found that file size matters for the Googles proxy. I suggest making the files as small as possible and see if this works. You can use your Gmail account and add a photo from the URL for verification. If GIF appears during the writing of the letter, you can get it.

Good coding.

0
Aug 26 '19 at 21:05
source share

I know this is an old question, but I met this problem. In my case, the images are stored in Google Cloud Storage. Interestingly, this link

 https://storage.cloud.google.com/{bla_bla}/logo.png 

returns 307 (temporary redirection) and a Location header containing something like

 https://{xxx}-apidata.googleusercontent.com/{bla-bla_bla}/logo.png?{zzz} 

It looks like GoogleImageProxy is not processing 307 correctly

0
Sep 04 '19 at 11:49 on
source share

This is March 6th, and you probably already understood this, but you thought that I would call others to help others. I found that jpg do not work in gmail. The PNG format works great. Sorry, I can’t explain why, but sometimes it’s better not to ask why. Use PNG!

-5
Mar 06 '14 at 16:29
source share



All Articles