Very simple email image embed

 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

  1. youtubize template tag by TheJester 6 years, 11 months ago
  2. "Youtube watch link to embed" custom tag. by I159 2 years, 7 months ago
  3. Simple "html email with images" sender by andres_torres_marroquin 3 years, 1 month ago
  4. hide emails with PIL - template filter by dekomote 4 years, 6 months ago
  5. Simple e-mail template tag by dchandek 6 years ago

Comments

ssadler (on May 15, 2009):

Example usage: from django.core.mail import EmailMessage from myproject import email_embed_image

img_content_id = 'main_image'
img_data = ''
open('/path/to/image', 'rb').read()
body = '<img src="cid:%s" />' % img_content_id

email = EmailMessage('title', body, 'aaa@bbb.ccc', ['aaa@bbb.ccc'])
email_embed_image(email, img_content_id, img_data)
email.send()

#

Tarken (on September 10, 2009):

This is exactly what I needed, thank you!

#

(Forgotten your password?)