Skip to main content

Send emails using Django template system

Project description

Send emails using Django template system

Documentation Status PyPI Package CircleCI Status

This is a tiny wrapper around the standard EmailMessage class and send_mail() function that provides an easy way to create email messages using the Django template system. Just pass template_name and context as the first parameters then use as normal.

Features

  • Built with OOP, KISS and flexibility in mind. Really small and simple, but yet full-featured (I hope).

  • Extends and mimics the built-in Django’s EmailMessage and send_mail(). Compatible as much as possible.

  • Fully supports Django template system including template inheritance (thanks to BradWhittington for the note about the problem).

  • Supports any possible template engines and loaders.

  • Supports serialisation (thanks to arjandepooter).

  • Fully covered with tests.

  • Tested with Django 1.4-1.9.

  • Compatible with Python 3.

Documentation

http://django-mail-templated.readthedocs

Quick start

Run:

pip install django-mail-templated

And register the app in your settings file:

INSTALLED_APPS = (
    ...
    'mail_templated'
)

Create template:

{% extends "mail_templated/base.tpl" %}

{% block subject %}
Hello {{ user.name }}
{% endblock %}

{% block body %}
{{ user.name }}, this is a plain text message.
{% endblock %}

{% block html %}
{{ user.name }}, this is an <strong>html</strong> message.
{% endblock %}

Send message:

from mail_templated import send_mail
send_mail('email/hello.tpl', {'user': user}, from_email, [user.email])

Advanced usage:

from mail_templated import EmailMessage

message = EmailMessage('email/hello.tpl', {'user': user}, from_email,
                       to=[user.email])
# TODO: Add more useful commands here.
message.send()

More useful info and examples at http://django-mail-templated.readthedocs.org

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

django-mail-templated-2.6.0.tar.gz (12.4 kB view details)

Uploaded Source

File details

Details for the file django-mail-templated-2.6.0.tar.gz.

File metadata

File hashes

Hashes for django-mail-templated-2.6.0.tar.gz
Algorithm Hash digest
SHA256 4ee7b34015ebedc889c64a3369c2346d35c41f5e193c0aa28f649daf496d9517
MD5 0541fe3a7900c154c295bead310c1b11
BLAKE2b-256 6e2256fd033f2dfd2a9db6f6be35ace213b2f22f0c08c3c5a36c515ee1885f0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page