Django Mail Template
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+)
Requirements
-
Django's email docs specify all requirements for sending mail with django.core.mail ( Django email).
-
django_mail_templateuses Django admin site, check official documentation for it's requirements: Django admin site. -
django_mail_templateuses Django CKEditor to let write rich text MailTeamplate.
Quick start
Installation and configuration
- Install
django_mail_templatefrom pypi:
pip install django-mail-template
- Add
'django_mail_template'and'ckeditor'to yourINSTALLED_APPSsetting:
INSTALLED_APPS = [
...
'ckeditor'
'django_mail_template',
]
- Run migrations to create django_mail_template models:
python manage.py migrate
- 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
()
You can also check django_mail_template test coverage at
Coverage
()
Related sites
Metadata
Release files for django-mail-template 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_mail_template-0.1.11.tar.gz | 20.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_mail_template-0.1.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.5 kB
Release files / django_mail_template-0.1.11.tar.gz
| Download URL | django_mail_template-0.1.11.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcb296308928c014089297b07195360c6b3392376dd7abab500b297287f5a7d0
|
|
BLAKE2b-256 checksum How to use checksums |
5ad61ce80bcb8f7a18527694a94ed2254663f7fa51ef0df83797b00b458b9773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / django_mail_template-0.1.11-py3-none-any.whl
| Download URL | django_mail_template-0.1.11-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecc4ccfebf5f28f8e8c6773a7a4b59d515fc9e03f88ef368e064b5f31f19a201
|
|
BLAKE2b-256 checksum How to use checksums |
a0c0c659216abc8da46e716362e30167d4822ea037f178e79dd71180a51ed22c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|