Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

amazon s3 - Gmail's broken image links when sending mails through Django

I'm sending an email using the SMTP protocol in Django. When I send the image link it is like this:

https://example.com/images/pic1.jpg

But Gmail converts it to something like this:

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

I tried the image URL proxy whitelist setting. It is showing the preview of the image.But image links are not working. img link broken

PS: I have also tried methods suggested here to no avail.

Update 1: The images are stored in the AWS s3 bucket. If I make them public then they work fine. But I can't make them public.Is there any other way?

question from:https://stackoverflow.com/questions/65880689/gmails-broken-image-links-when-sending-mails-through-django

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The images are stored in the AWS s3 bucket. If I make them public then they work fine. But I can't make them public.Is there any other way?

The short answer is "no" if you want to keep referencing image through URLs as GMail's image proxy needs access to your images over the "public" internet one way or another.

This question is a bit off topic as it has little to do with Django but if you're using GMail for business you can configure which URLs should not go through the proxy. This should allow you to prevent images served from your "private" S3 bucket URL from being proxied. Note that this will only work for GMail accounts within your business domain; the images will be proxied and fail to load if the email is sent to a non-business or a different business Gmail account for example.

One another way you could avoid proxying completely it to attach the image in the email instead of referring to it through an URL. You can refer to this answer for how to achieve that https://stackoverflow.com/a/3787766/70191.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...