0

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?

The Mask
  • 390
  • 3
  • 17

1 Answers1

0

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.

Simon Charette
  • 5,009
  • 1
  • 25
  • 33
  • Thank you for the response, Simon. I already tried the proxy whitelist method. It is showing me the image preview in my google workspace account. But when I send mail from my custom domain to someuser@gmail.com then I'm encountering this problem. I also tried the second method, but it did not look nice since images were attached at the bottom of the mail body. – The Mask Jan 30 '21 at 14:11
  • Are there any settings like CORS or server configuration that I can perform to achieve this? Thanks in advance. – The Mask Jan 30 '21 at 14:13
  • > But when I send mail from my custom domain to someuser@gmail.com then I'm encountering this problem. yeah this won't work for recipients outside the domain your own. > I also tried the second method, but it did not look nice since images were attached at the bottom of the mail body. It should work if you define your images with `src="cid:..."` as explained in https://stackoverflow.com/questions/19171742/send-e-mail-to-gmail-with-inline-image-using-python. Otherwise you could try base `base64` images https://stackoverflow.com/questions/3279523/base64-images-to-gmail – Simon Charette Jan 30 '21 at 18:22
  • The second method worked but the mail size is increased after I added images as attachments. I want to create a reference URL for the images without attaching them. – The Mask Jan 30 '21 at 19:08
  • How do other companies perform it? Adding user images in the newsletter without attaching them like LinkedIn and other social sites. – The Mask Jan 30 '21 at 19:14
  • They simply serve their images from a publicly accessible location. I think you should revisit your decision of not making your S3 bucket accessible publicly through HTTP. If you don't want it to be public because you're stashing private data in there as well create two distinct buckets for your two different purposes. – Simon Charette Jan 30 '21 at 19:57
  • Hey Simon,I'm facing this issue again. Wonder if you could help me out here? – The Mask Feb 16 '21 at 14:38
  • I have made my bucket public and serving images using a custom domain.But still, Gmail showing the above behavior. – The Mask Feb 16 '21 at 14:40