Skip to main content

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
MAILGUN_API_KEY = 'YOUR API KEY'
MAILGUN_DOMAIN = 'MAILGUN_DOMAIN'

# The engine is in charge of sending email using a backend system.
engine = templatemail.engines.mailgun.MailgunDeliveryEngine(
    api_key=MAILGUN_API_KEY,
    domain_name=MAILGUN_DOMAIN)
    
# The mailer is in charge of rendering templates and sending them using an engine.
mailer = templatemail.TemplateMail(
    template_dirs=['email_templates'],
    delivery_engine=engine)

# Using the two, you can send templates.
template_name = 'welcome.html'
result = mailer.send_email(
    to_addresses=['test@example.com'],
    from_address='from@example.com',
    template_name=template_name,
    user_name='Ken'
)

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.

Installation

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.

© 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.

Metadata

Release files for templatemail 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for templatemail 1.1.0
File Size Uploaded
templatemail-1.1.0.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for templatemail 1.1.0
File Interpreter ABI Platform
templatemail-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.0 kB

Release files / templatemail-1.1.0.tar.gz

Download URL templatemail-1.1.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
84979156922f573c32ec41c53c17618924f3c07a8fd3bcd0975e55579291c174
BLAKE2b-256 checksum
How to use checksums
d3bfa4c0892c2900b06ead523dea059452730f07b12f3ff42e04340cd3ddea26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / templatemail-1.1.0-py3-none-any.whl

Download URL templatemail-1.1.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dd4913f4021477fc3a6ee39b96835fd896e1f86c09e996b43ba485485010aa4
BLAKE2b-256 checksum
How to use checksums
0c36929b0f215ce7b2c310bda9e13d110b6460bc079a368b7da90bb095be9c32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

1 release file

0.2.0

1 release file

0.1.7

1 release file

0.1.6

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page