This is a simple way to embed images in emails, rather than use absolute links, which many clients will not show by default. It has not undergone extensive testing but it should get you started. Comments / suggestions welcome.
1 2 3 4 5 6 7 8 9 10 | from email.MIMEImage import MIMEImage
def email_embed_image(email, img_content_id, img_data):
"""
email is a django.core.mail.EmailMessage object
"""
img = MIMEImage(img_data)
img.add_header('Content-ID', '<%s>' % img_content_id)
img.add_header('Content-Disposition', 'inline')
email.attach(img)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Example usage: from django.core.mail import EmailMessage from myproject import email_embed_image
#
This is exactly what I needed, thank you!
#
Please login first before commenting.