sendgrid / sendgrid-python

The Official Twilio SendGrid Python API Library
https://sendgrid.com
MIT License
1.55k stars 714 forks source link

Inline images failing #951

Open mphelp opened 4 years ago

mphelp commented 4 years ago

@thinkingserious and other great package maintainers:

Inline image CID troubles!

I am able to successfully attach the PNG image. However, I cannot get it to appear inline in Gmail, Outlook, or iCloud. NOTE: Previews do show in Gmail and iCloud. But no previews in Outlook. As an aside, iCloud shows the image alt. The emails are sent successfully otherwise.

Mail obj dump

...
'content': 
    [{'type': 'text/html', 
      'value': '<h3> Forecast wape on scn unt qy by gtin no</h3><img src="cid:viz_0" alt="Inline picture of  
                  Forecast wape on scn unt qy by gtin no"/>'}], 
       'attachments': 
              [{'content': '...', 'type': 'image/png', 
               'filename': '_Forecast_wape_on_scn_unt_qy_by_gtin_no.png', 'content_id': 'viz_0'}]}
...

I was following THIS documentation: https://sendgrid.com/blog/embedding-images-emails-facts/

Technical details:

eshanholtz commented 4 years ago

Hi @mphelp

According to that documentation, it warns that using Content ID Inline images does not always work for web-based email clients, like Gmail. The next section, Inline Embedding (Base64 Encoding), provides directions on how to attach an image inline using the Base64 encoding of that image. I recommend trying this method, since Content ID images are not working for you on those email clients.

mphelp commented 4 years ago

@eshanholtz It turns out that I wasn't including the "disposition" and it defaults to attachment and not inline. After setting it to "inline," the images show up inline in Gmail, Outlook, and iCloud!

attachment.disposition = Disposition('inline')

Note: The attachment use case in this repo doesn't cover inline attachment. It'd be good to include one. Do you agree? If so I could provide a code sample that matches the other use case examples.

eshanholtz commented 4 years ago

I agree that would be a very helpful example to include. Please submit a PR for review! Thanks!