Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1.86 KB

README.md

File metadata and controls

49 lines (37 loc) · 1.86 KB

django-email-multi-related

Send HTML emails with embedded images in Django from templates. Required Django >= 1.4 and BeautifulSoup4 with lxml http://www.crummy.com/software/BeautifulSoup/bs4/doc/#parser-installation parser for automatically generat text version of email.

Send emails using django templates

Add emailmultirelated to settings.INSTALLED_APPS

from emailmultirelated.mail import EmailMultiRelated
email = EmailMultiRelated('email title', to=['nex2hex@gmail.com'])
email.set_body_template('email_template.html', {})
email.send()

Example of email_template.html

{% load emailmultirelated %}

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
  <body>
    <img src="{% email_embedded_media "path_to_image_in_media_root_dir.png" %}" alt="" />
    <img src="{% email_embedded_static "path_to_image_in_static_root_dir.png" %}" alt="" />
  </body>
</html>

Send emails using Jinja2 templates

Required Jinja2

from emailmultirelated.mail import EmailMultiRelated
email = EmailMultiRelated('email title', to=['nex2hex@gmail.com'])
email.set_body_template('email_template.html', {}, using='jinja')
email.send()

Example of email_template.html

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
  <body>
    <img src="{% email_embedded_media "path_to_image_in_media_root_dir.png" %}" alt="" />
    <img src="{% email_embedded_static "path_to_image_in_static_root_dir.png" %}" alt="" />
  </body>
</html>

How write HTML Emails