Skip to main content

Django-AppMail

PyPI

Django app for managing transactional email templates.

Compatibility

This project requires Python 3.12+ and Django 5.2-6.0.

Background

This project arose out of a project to integrate a large transactional Django application with Mandrill, and the lessons learned. It also owes a minor h/t to this project from 2011 (https://github.com/hugorodgerbrown/AppMail).

The core requirement is to provide an easy way to add / edit email templates to a Django project, in such a way that it doesn't require a developer to make changes. The easiest way to use templated emails in Django is to rely on the in-built template structure, but that means that the templates are held in files, under version control, which makes it very hard for non-developers to edit.

This is not a WYSIWYG HTML editor, and it doesn't do anything clever. It doesn't handle the sending of the emails - it simply provides a convenient mechanism for storing and rendering email content.

from appmail.models import EmailTemplate, AppmailMessage

def send_order_confirmation(order_id):
    order = Orders.objects.get(id=order_id)
    template = EmailTemplate.objects.current('order_confirmation')
    context = { "order": order }
    message = AppmailMessage(
        template=template,
        context=context,
        to=[order.recipient.email]
    )
    message.send()

The core requirements are:

  1. List / preview existing templates
  2. Edit subject line, plain text and HTML content
  3. Use standard Django template syntax
  4. Support base templates
  5. Template versioning
  6. Language support
  7. Send test emails
  8. Log emails sent (if desired)

Email logging (v2)

From v2 on, it is possible to log all emails that are sent via AppmailMessage.send. It records the template, context and the rendered output, so that the email can be views as sent, and resent. It will attempt to record the User to whom the email was sent, as well as the email address. This is dependent on there being a unique 1:1 match from email to User object, but can prove useful in tracking emails sent to users when they change their email address.

Template properties

Individual templates are stored as model objects in the database. The standard Django admin site is used to view / filter templates. The templates are ordered by name, language and version. This combination is unique. The language and version properties have sensible defaults (version=settings.LANGUAGE_CODE and version=0) so don't need to set if you don't require it. There is no inheritance or relationship between different languages and versions - they are stored as independent objects.

# get the default order_summary email (language = settings.LANGUAGE_CODE)
template = EmailTemplate.objects.current('order_summary')
# get the french version
template = EmailTemplate.objects.current('order_summary', language='fr')
# get a specific version
template = EmailTemplate.objects.version('order_summary', 1)

Template syntax

The templates themselves use standard Django template syntax, including the use of tags, filters. There is nothing special about them, however there is one caveat - template inheritance.

Template inheritance

Although the template content is not stored on disk, without re-engineering the template rendering methods any parent templates must be. This is annoying, but there is a valid assumption behind it - if you are changing your base templates you are probably involving designers and developers already, so having to rely on a developer to make the changes is acceptable.

Sending test emails

You can send test emails to an email address through the admin list view.

EmailTemplate admin
change form

The custom admin action 'Send test emails' will redirect to an intermediate page where you can enter the recipient email address and send the email:

There is also a linkon individual template admin pages (top-right, next to the history link):

EmailTemplate admin
change form

Tests

There is a test suite for the app, which is best run through tox.

License

MIT

Contributing

Usual rules apply:

  1. Fork to your own account
  2. Fix the issue / add the feature
  3. Submit PR

Please take care to follow the coding style - and PEP8.

Metadata

Release files for django-appmail 8.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 django-appmail 8.0
File Size Uploaded
django_appmail-8.0.tar.gz 20.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-appmail 8.0
File Interpreter ABI Platform
django_appmail-8.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.6 kB

Release files / django_appmail-8.0.tar.gz

Download URL django_appmail-8.0.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bfe5ade372007a32d8ba540f12870c3d9abedcebd73d60cc48378dd271505c7c
BLAKE2b-256 checksum
How to use checksums
a828b28b945e06ae0a5c3abbb7c72a2e1ab35bcdad37992d06e88f334270a87b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / django_appmail-8.0-py3-none-any.whl

Download URL django_appmail-8.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81b48042f54711e3f029e9dbf119372ccea30bde6a11e45703dbe45e5819169d
BLAKE2b-256 checksum
How to use checksums
54459c438acb97436098daec7db684e576ee3ff285b57b7cd4b33388d147141a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

8.0 This release

2 release files

7.0

2 release files

6.0

2 release files

5.0.0

2 release files

4.0

2 release files

3.0

2 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0

2 release files

1.3.1

2 release files

1.3

2 release files

1.1

1 release file

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.7

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

0.4.2

2 release files

0.4.1

1 release file

0.4

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

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