mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Improve inline-image handling
* Add filename param to attach_inline_image * Add attach_inline_image_file function (parallels EmailMessage.attach and attach_file) * Use `Content-Disposition: inline` to decide whether an attachment should be handled inline (whether or not it's an image, and whether or not it has a Content-ID) * Stop conflating filename and Content-ID, for ESPs that allow both. (Solves problem where Google Inbox was displaying inline images as attachments when sent through SendGrid.)
This commit is contained in:
@@ -107,7 +107,7 @@ or any other supported ESP where you see "mailgun":
|
||||
.. code-block:: python
|
||||
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
from anymail.message import attach_inline_image
|
||||
from anymail.message import attach_inline_image_file
|
||||
|
||||
msg = EmailMultiAlternatives(
|
||||
subject="Please activate your account",
|
||||
@@ -117,7 +117,7 @@ or any other supported ESP where you see "mailgun":
|
||||
reply_to=["Helpdesk <support@example.com>"])
|
||||
|
||||
# Include an inline image in the html:
|
||||
logo_cid = attach_inline_image(msg, open("logo.jpg", "rb").read())
|
||||
logo_cid = attach_inline_image_file(msg, "/path/to/logo.jpg")
|
||||
html = """<img alt="Logo" src="cid:{logo_cid}">
|
||||
<p>Please <a href="http://example.com/activate">activate</a>
|
||||
your account</p>""".format(logo_cid=logo_cid)
|
||||
|
||||
Reference in New Issue
Block a user