Skip to main content

Application for creating mails templates with context variables. There is a double mapping between a mail template and process configuration so is possible to change used mail template of a process at run time.

Project description

Django roles access

Django Mail Template

Build Status codecov

A very simple Django application for:

  • Provide basic template features for mails subjects and bodies.

  • Provide needed infrastructure to let administrative users create/edit mails used by applications.

Description

django_mail_template is a very simple application to create mails templates with context variables, and then send mails with context variables replaced with values. Mails templates are created with Django admin interface.

For example, if context variables are: first_name and last_name, while cycling a collection of people (clients, providers, and like) is possible to send a mail to each of them using their first name and last name to replace the context variables in MailTemplate body or subject:

Dear {first_name} {last_name} have a great new year!!!

Also with indirect use between MailTemplate and Configuration is possible to change at run time the mail template mapped to a piece of code through a Configuration instance.

For example, create two mail template: one with christmas greeting text and subject, and other mail template with new year greeting text and subject. Then the same process (code) used in upper example can be used to send christmas and new year greeting to all people.

Change which mail template is used by which process in Django admin interface.

Works with:

  • Django 1.11+ (Python 3.5+)

  • Django 2+ (Python 3.5+)

  • Django 3+ (Python 3.5+)

  • Documentation

Requirements

  1. Django's email docs specify all requirements for sending mail with django.core.mail ( Django email).

  2. django_mail_template uses Django admin site, check official documentation for it's requirements: Django admin site.

  3. django_mail_template uses Django CKEditor to let write rich text MailTeamplate.

Quick start

Installation and configuration

  1. Install django_mail_template from pypi:
    pip install django-mail-template
  1. Add 'django_mail_template' and 'ckeditor' to your INSTALLED_APPS setting:
    INSTALLED_APPS = [
        ...
        'ckeditor'
        'django_mail_template',
    ]
  1. Run migrations to create django_mail_template models:
    python manage.py migrate
  1. Run the collectstatic management command:
    python manage.py collectstatic

Use Django Mail Template

1. Direct use

You can simple use django_mail_template to send mails:

    from django_mail_template.models import MailTemplate

    mail_template = MailTemplate(title="A mail Title", from="a@b.com",
                                 to="b@b.com",
                                 subject="Django Mail Template quick start.")
    mail_template.send()

2. Template features

django_mail_template's basic template feature is based in variables replacement with Python string format:

    from django_mail_template.models import MailTemplate

    ...
    mail_template = MailTemplate.create(
        title="First mail template",
        from="a@b.com",
        subject="Hello {client}.",
        body="Dear {client}: We are delivering your {product}."
    )

    ...
    mail_template.to = ["bobtheclient@c.com"]
    mail_template.send({"client": "Bob TheClient",
                        "product": "Great product"})

Administrative users can create or edit MailTemplate using Django admin site and redact text using Python string format.

3. Indirect use

Is also possible to use an indirect call through Configuration data model. In Django admin site (or by code) you can create:

    a_mail_template_greeting = MailTemplate.objects.create(
        title="First mail template",
        from="a@b.com",
        subject="Hello {client}.",
        body="Dear {client}: We wish you {greeting}.")

    configuration = Configuration.objects.create(
        process="clients_greeting",
        mail_template=a_mail_template_greeting
    )

Then in code

    from django_mail_template.models import Configuration

    mail_template = Configuration.get_mail_template("clients_greeting")
    # Cycle through clients
        mail_template.to = client.email
        mail_template.send({"client": client.name,
                            "greeting": "A great mew year!!!"})

4. Django admin interface

When django_mail_template is installed, and migrations applied, Django admin site will expose to administrative users a new section with title Django Mail Template. User can manage MailTempaltes and Configurations from there:

  • MailTemplate: Users can redact mails (create, edit, delete).

  • Configuration: If code points to Configurations (indirect use), administrative users can change mapped MailTemplate to use new mail template without changing code.

  • Test created mail templates

More about Django mail template

You can check the django_mail_template test execution at Travis CI integration (Build Status)

You can also check django_mail_template test coverage at Coverage (codecov)

Related sites

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_template-0.1.11.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

django_mail_template-0.1.11-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file django_mail_template-0.1.11.tar.gz.

File metadata

  • Download URL: django_mail_template-0.1.11.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.7

File hashes

Hashes for django_mail_template-0.1.11.tar.gz
Algorithm Hash digest
SHA256 bcb296308928c014089297b07195360c6b3392376dd7abab500b297287f5a7d0
MD5 b9daf212d56dd3dd9487799d126955e3
BLAKE2b-256 5ad61ce80bcb8f7a18527694a94ed2254663f7fa51ef0df83797b00b458b9773

See more details on using hashes here.

File details

Details for the file django_mail_template-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: django_mail_template-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.7

File hashes

Hashes for django_mail_template-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 ecc4ccfebf5f28f8e8c6773a7a4b59d515fc9e03f88ef368e064b5f31f19a201
MD5 6994a8c63d51735b4cb6e081c7c720a7
BLAKE2b-256 a0c0c659216abc8da46e716362e30167d4822ea037f178e79dd71180a51ed22c

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