Skip to main content

Django app for managing localised email templates.

Project description

https://travis-ci.org/yunojuno/django-appmail.svg?branch=master https://badge.fury.io/py/django-appmail.svg

Django-AppMail

Django app for managing transactional email templates

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

def send_order_confirmation(order_id):
    order = Orders.objects.get(id=order_id)
    template = EmailTemplate.objects.current('order_confirmation')
    context = { "order": order }
    # create_message accepts EmailMultiAlternatives constructor kwargs
    # and returns a standard Django email object which can be updated / sent.
    message = template.create_message(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

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:

screenshots/appmail-test-email-send.png

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.

Licence

MIT

Contributing

Usual rules apply:

  1. Fork to your own account

  2. Create a branch, fix the issue / add the feature

  3. Submit PR

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

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-appmail-0.6.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_appmail-0.6-py2-none-any.whl (28.5 kB view details)

Uploaded Python 2

File details

Details for the file django-appmail-0.6.tar.gz.

File metadata

  • Download URL: django-appmail-0.6.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-appmail-0.6.tar.gz
Algorithm Hash digest
SHA256 89ca917b4f85515b8671fd28598cd326fe4c5b39f3dfec8bbd0e0c70b26a388f
MD5 aa41499353c443753edeb5738b86bb99
BLAKE2b-256 4975e03404084e77ddda96bee61cee587f0cc14ccaad48747b557d8c24eb0435

See more details on using hashes here.

File details

Details for the file django_appmail-0.6-py2-none-any.whl.

File metadata

File hashes

Hashes for django_appmail-0.6-py2-none-any.whl
Algorithm Hash digest
SHA256 683e4c17dca3a12eebfad6d5c5b0ee17f0ea4161d954d893d11e2f0c3edb1d18
MD5 b10d829d1c9dffd18cb0bbd1247c52b3
BLAKE2b-256 63fae72db5a7119f9349f8dce09c973257a406cbae2b7a9b08bbc0c57aa612c1

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