Skip to main content
Version:
0.3.9

Build status Code quality checks black Coverage status

python-versions django-versions pypi-version

Django e-mail templates!

Many projects have a well defined set of events that trigger an outgoing e-mail, and the sensible thing is to template these out.

However, doing code updates and deployments for small template tweaks are a bit cumbersome and annoying.

This project aims to solve that - define the types of templates in the code, and edit the actual templates in the front-end. Templates are validated on syntax and required/optional content.

This project also aims to solve the HTML email template problems that you can have when supporting all email clients. This was also used by foundation for email. Foundation for email is a good way to build your initial email template on development mode. It will generate a separate html file and css file.

For e-mail sending and logging, we recommend using a solution such as Django Yubin.

This is only tested on a postgres database.

Supported are:

  • python 3.11, 3.12, 3.13

  • Django 4.2, 5.2

  • PostgreSQL

Warning

This project is currently in development and not stable.

Installation

Install with pip:

pip install mail_editor

Add ‘mail_editor’ to the installed apps:

# settings.py

INSTALLED_APPS = [
    ...
    'mail_editor',
    'ckeditor',
    ...
]

Add the urls:

# urls.py

path('mail-editor/', include('mail_editor.urls', namespace='mail_editor')),

Using the template

There are 2 templates that you can use.

The _base.html, this template can not be edited by the user. This will only be rendered when the email is send.

The _outer_table.html, this template can be edited by the user and will be loaded in the editor in the admin. This template will be saved in the database with the modifications.

You can use the templates in some different ways. The shortest way is:

from mail_editor.helpers import find_template

def email_stuff():
    template = find_template('activation')

    context = {
        'name': 'Test Person',
        'site_name': 'This site',
        'activation_link': 'https://github.com/maykinmedia/mail-editor',
    }

    template.send_email('test@example.com', context)

Settings

The following settings are an example:

MAIL_EDITOR_CONF = {
    'activation': {
        'name': gettext_noop('Activation Email'),
        'description': gettext_noop('This email is used when people need to activate their account.'),
        'subject_default': 'Activeer uw account voor {{site_name}}',
        'body_default': """
            <h1>Hallo {{ name }},</h1>

            <p>Welkom! Je hebt je geregistreerd voor een {{ site_name }} account.</p>

            <p>{{ activation_link }}</p>
        """,
        'subject': [{
            'name': 'site_name',
            'description': gettext_noop('This is the name of the site. From the sites'),
            'example': gettext_noop('Example site'),
        }],
        'body': [{
            'name': 'name',
            'description': gettext_noop('This is the name of the user'),
            'example': gettext_noop('Jane Doe'),
        }, {
            'name': 'site_name',
            'description': gettext_noop('This is the name of the site. From the sites'),
            'example': gettext_noop('Example site'),
        }, {
            'name': 'activation_link',
            'description': gettext_noop('This is the link to activate their account.'),
            'example': gettext_noop('/'),
        }]
    },
    ...
}

These settings are usefull to add:

# These settings make sure that CKEDITOR does not strip any html tags. like <center></center>
CKEDITOR_CONFIGS = {
    'mail_editor': {
        'allowedContent': True,
        'contentsCss': ['/static/css/email.css'], # Enter the css file used to style the email.
        'height': 600,  # This is optional
        'entities': False, # This is added because CKEDITOR escapes the ' when you do an if statement
    }
}

You can set template variables to all of the mail templates in the following fashion.

# static dictionary
MAIL_EDITOR_BASE_CONTEXT = {
    'url': 'http://www.maykinmedia.nl',
}

# import path to callable that returns a dictionary
MAIL_EDITOR_DYNAMIC_CONTEXT = "dotted.path.to.callable"

Installation

Install with pip:

pip install mail_editor

Local development

To install and develop the library locally, use:

.. code-block:: bash

pip install -e .[tests,coverage,release]

When running management commands via django-admin, make sure to add the root directory to the python path (or use python -m django <command>):

export PYTHONPATH=. DJANGO_SETTINGS_MODULE=testapp.settings
django-admin check
# or other commands like:
django-admin migrate
django-admin createsuperuser
django-admin runserver
# django-admin makemessages -l nl

Metadata

Release files for mail-editor 0.3.9

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

Source distribution (sdist)

Source distribution for mail-editor 0.3.9
File Size Uploaded
mail_editor-0.3.9.tar.gz 108.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mail-editor 0.3.9
File Interpreter ABI Platform
mail_editor-0.3.9-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 139.3 kB

Release files / mail_editor-0.3.9.tar.gz

Download URL mail_editor-0.3.9.tar.gz
Size 108.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d290d3633889ae135dc81eb9a3adb7b66d6fa485cd551d0b8c9cc98266ff3b96
BLAKE2b-256 checksum
How to use checksums
f42fc6d416a9947313fa7e9a7ebfc5827f1f0720760763293645966f455c3dfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.

Transparency log

Release files / mail_editor-0.3.9-py2.py3-none-any.whl

Download URL mail_editor-0.3.9-py2.py3-none-any.whl
Size 31.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
82fc8a984aab137eb40fbd716afbd425d537e950370b4dafe697890e8f6a5907
BLAKE2b-256 checksum
How to use checksums
e5efd11d1139ad90cb1ffeb098d460503e679830dcd7f2a7ed079882a5fd5904
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.9 This release

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.2.2

1 release file

0.2.1

1 release file

0.2.0

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