Gmail's new image caching is breaking image li

2020-01-24 10:34发布

I've got some automatic emails that are sent out upon signup completion for my site.

Until recently, they worked fine. Now Google's new system is rewriting the images and storing them in it's cache (supposedly)

However, Google's new rewriting of my image links are completely breaking them, giving a 500 error and a broken link image.

Lets say my normal image url is:

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

Google is rewriting this to:

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

However, there is nothing at that URL.

Email showing image errors

So, either there is something wrong with the links that are being created by Google or the images are just not being uploaded to the googleusercontent server, but I have no idea how to solve the issue.

Im using PHP, the phpmailer library and a Ubuntu server on Amazon EC2, but Im not sure that is related to the issue.

15条回答
劳资没心,怎么记你
2楼-- · 2020-01-24 11:01

I think I have figured out the GoogleImageProxy issue.

This is something related to CACHING concept. suppose, you have recently deployed your php code on your server but you forgot to upload images. you tested once with your email logic. your system generated an HTML email. When this email will hit the gmail server GoogleImageProxy will try to fetch and store the images from your site to its own proxy server. while fetching the images, GoogleImageProxy found some 404 statuses against your missing images and 403 against some protected images. GoogleImagesProxy has stored these statuses into its own proxy server.

Now tried to open your email, you noticed some 404 statuses against your images. This is something understandable. You immediately realized that you forgot to upload some images, so you uploaded them to your server. and also you have fixed some permissions against protected images.

You are all done now. Now you try to run your php-email script once again. As a result you receive another email in your Gmail or Hotmail inbox. you had fixed all the issues with your images. Now the images must be displayed in your email content. but you are still unable to see the images.

Ah, possibly you forgot to clear your browser's cache. Clear your browser's cache and load the gmail or hotmail page once again. But the result will be still the same. Try to apply dozens of fixes/patches and try to run your php-email script a thousands time. But the result will be still the same. No improvement.

THE REAL PROBLEM

What the hell is going on? Let me explain it to you. Go to your access log and try to find requests from GoogleImageProxy. You'll be surprised to see that there will be only 2 or 3 three requests from GoogleImageProxy depending on the number of different images used in your email. GoogleImageProxy never tried to fetch images Even after you have fixed the issues with your images by uploading missing images and setting permissions for protected images. Why? Clearing your browser's cache has no impact. GoogleImageProxy will never fetch the fresh images even for your newer email because the images are now cached into GoogleImageProxy along with their last status code and not cached in your own browser's.

GoogleImageProxy has set its own expiry date for the images. I think one month. so now the fresh copy of images will be fetch after expiry date. I mean after one month. You can not force GoogleImageProxy to fetch the images. But its important for you to display images in your email. What can be the solution?

THE SOLUTION

Following is the only way to force GoogleImageProxy to fetch your images

  • Rename your images to something else with png, jpg or gif extensions only.
  • Don't use any kind of query string in your image url like ?t=34343
  • your image must include png, jpg or gif as an extension.
  • your image url must be mapped onto your image directly.
  • If you need to use some proxy url for your protected images then your response must include the proper header like Content-Type: image/jpeg
  • File extension and content-type header must match
  • Status-code must be 200 instead of 403, 500 etc

IMPORTANT NOTE

Try to repeat the whole process for every run of php-email script. because every time GoogleImageProxy will cache your images and you'll have to repeat the same process for every new try.

Hopefully this will fix the issue for most of the people.

查看更多
爷的心禁止访问
3楼-- · 2020-01-24 11:03

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

  • Open email in new browser , it shows new image

  • Ctrl+f5 (forces a cache refresh) in the chrome (my default browser) , also shows new image

查看更多
ら.Afraid
4楼-- · 2020-01-24 11:07

I was having a similar issue, but it was caused by the length of the URL. Google generates the following URL when caching an image from gmail:

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

The hash generated is based on the URL of the image, but the size will vary based on characters used. I ran several tests with different sized URLs, and found the cached image would fail to load consistently (400/Invalid Request) if the hash exceeds 2076 characters in length (close to 2048 bytes + meta? not sure).

Again, the image URL could generate a hash that exceeds this many characters at ~1000 special characters, or 1500+ simple characters. If the hash exceeds 2076 characters in length, the request fails.

I realize this is an old post, but hopefully this helps other devs scouring Google

查看更多
神经病院院长
5楼-- · 2020-01-24 11:11
  1. Is it working from Outook/hotmail? It should then we can isolate it as google issue. In your case it is not.
  2. Size of the image can be a problem. Try to reduce it and see
  3. www.mysite.com this site might be accessible from your system. But is it also accessible from google server?
  4. Try changing extension.. this is the trick: You might have tried several things but it would still fetch from cache(which invalidates your efforts) but when the extension changes, it fetches again and all the work you did before comes into play and if it works you might think it is the 'extension' that did the trick!! (like many of those who speaks about extensions)
查看更多
\"骚年 ilove
6楼-- · 2020-01-24 11:14

Check that the content-type returned for the image file by your server is correct.

You can check this using Fiddler.

查看更多
狗以群分
7楼-- · 2020-01-24 11:19

Make sure that Gmail is request your image over http, not https.

Lets say your normal 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's proxy don't cache https.

查看更多
登录 后发表回答