Package: django-html-emailer
Django HTML EmailerA utility app for sending HTML emails in Django 1.7+:UsesHTML Email Boilerplate v0.5Inlines CSS (per the boilerplate's instructions) usinginlinestyler.Renders message body from Markdown or from text and HTML parts that you give.InstallationInstall this module:pip install django-html-emailerAddhtmlemailerto your Django settings's INSTALLED_APPS.Basic UsageHere's a quick example for how to send a message:from htmlemailer import send_mail

send_mail(
	"htmlemailer/example",
	"My Site <mysite@example.org>",
	["you@recipient.com"],
	{
		"my_message": "Hello & good day to you!"
	})Replace the recipient address with your email address. This should send you a message using the example template.Your Templateshtmlemailer composes your actual email from a series of templates. Usually you have:A template storing the actual content of your email (either a Markdown template or a pair of templates, one for the HTML part and one for the plain text part), which extends...A template that has the general design of all of your emails (CSS, header, footer), akin to yourbase.htmlfor your site (a pair of templates, one for HTML and one for text), which extends...The HTML Email Boilerplate, which we've already converted into a template.A..._subject.txttemplate which generates the subject line of the email (it's also a template so you can use variables etc. in it).First copy the example "general design" template files into your project's templates path, naming them as you like. Copy them from:htmlemailer/templates/htmlemailer/example_template.txthtmlemailer/templates/htmlemailer/example_template.htmlThen copy the example "actual content" template files into your project:htmlemailer/templates/htmlemailer/example_subject.txtand eitherhtmlemailer/templates/htmlemailer/example.mdif you want to use a single Markdown file orhtmlemailer/templates/htmlemailer/example.txthtmlemailer/templates/htmlemailer/example.htmlif you want to explicitly set the text and HTML parts of the message separately.You can change the path and file names, except the set of files must have thesamepath name up to.md,.txt,.html, and_subject.txt. That's how the module knows they go together (note how you don't include the file extension in the call tosend_mail).If you changed the path of the general design templates, you'll have to update the{% extends ... %}template tags inexample.mdorexample.txtandexample.htmlto point to the new path. You can of course have more than one email by creating a new set of.md,.txt,.html, and_subject.txtfiles at a different path.Lastly, in your call tosend_mail, update the first argument to specify the location of your email templates. Just specify the common part of the path name of the three files. In this case, it's justhtmlemailer/example. The.md,.txt,.html, and_subject.txtwill be added by the library.Advanced Usagesend_mailalso takes an optionalfail_silentlyboolean argument (default is False), and it passes other keyword arguments on to Django'sEmailMessageconstructor, so you can also passheadersandconnection.IfDEFAULT_TEMPLATE_CONTEXTis set in your settings, then it should be a dictionary with default template context variables passed into your email templates.Notes on MarkdownMarkdown messages are rendered into HTML using CommonMark (specification,library). The text part of the message is rendered using a special Markdown-to-text renderer, because raw Markdown doesn't always look professional (especially links and images).The Markdown is renderedfirstprior to running the Django template engine. So you cannot cause Markdown to be inserted into the email through template context variables. This is by design.Also note that the{% extends ... %}tag at the top of the Markdown message body template does not contain the.txtor.htmlfile extension. The library inserts the right file extension for the general design template prior to rendering into HTML and text.Note: The CommonMark library is monkey-patched to turn off escaping of {'s and }'s in URLs (to allow for template tags to appear within links). If you are using CommonMark elsewhere in your application, that might affect you if you are creating Markdown documents with these characters in URLs (which is probably bad anyway).Testing (Library Developers)A test Django project is included. To use:cd test_project
pip3 install inlinestyler commonmark commonmarkextensions
python3 manage.py test_html_email example
python3 manage.py test_html_email example2This will output test emails (a MIME message) to the console.exampleuses separate text and HTML parts.example2uses a single Markdown body file.LicenseThis project and the (upstream) boilerplate code are available under the MIT license.For Project MaintainersTo publish a universal wheel to pypi, update the version number in setup.py, then:pip3 install twine
rm -rf dist
python3 setup.py bdist_wheel --universal
twine upload dist/*
git tag v1.0.XXX
git push --tags