Skip to main content

Templated Email for Python

Project description

Build Status

Welcome to TemplateMail

TemplateMail is a simple Python library that solves most projects' email templating and delivery needs with minimal hassle. Suppose you want to send a welcome email to a new user using Mailgun:

import templatemail
import templatemail.engines.mailgun

# Credentials for Mailgun

# The engine is in charge of sending email using a backend system.
engine = templatemail.engines.mailgun.MailgunDeliveryEngine(
# The mailer is in charge of rendering templates and sending them using an engine.
mailer = templatemail.TemplateMail(

# Using the two, you can send templates.
template_name = 'welcome.html'
result = mailer.send_email(

welcome.html is an email template used to render the subject, html, and text versions of an email. Let's have a look at email_templates/welcome.html:

{% block subject %}Welcome to our system{% endblock %}
{% block html_body %}
<h1>Welcome to our system, {{ user_name }}</h1>
<p>We think you'll really enjoy it here.</p>
{% endblock %}
{% block text_body %}
Welcome to our system, {{ user_name }}

We think you'll really enjoy it here.
{% endblock %}

The subject block renders the subject, while html_body and text_body render the HTML and text versions of the email respectively. The work of composing the correct mime envelope, as well as delivery, is handled by an engine. At this time, TemplateMail has native Mailgun and SMTP backends, however you are also free to write your own. (See Writing your own engine)

It's that simple.


You can install templatemail like any other Python module.

pip install templatemail

NOTE: Only Python 3 is supported.

Read More

Read the documentation online at Read The Docs.

Get in touch

Have a pull request or an issue? Use Github.

Legal stuff

© Copyright 2019 Ken Kinder. Includes work from Mailgun, which is © Copyright 2014 Mailgun.

TemplateMail is licensed under the Apache 2.0 license. See LICENSE for details.

Includes templates from the Mailgun Responsive Templates repository. See LICENSE-mailgun-templates for details on its license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

templatemail-1.0.0.tar.gz (10.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page