Django MJML Email
Django MJML Email is a package that allows Django developers to write email templates using the MJML language. This tool simplifies the creation of responsive and well-structured emails.
What is MJML?
From the documentation of the project:
MJML is a markup language designed to reduce the pain of coding a responsive email. Its semantic syntax makes it easy and straightforward and its rich standard components library speeds up your development time and lightens your email codebase. MJML’s open-source engine generates high quality responsive HTML compliant with best practices.
Then what?
While the original compiler is written in Javascript and runs on Node.js, this package leverages
mrml, a rust implementation of mjml through a
python package with the same name.
The rust port is almost complete, it lacks a single feature: https://github.com/jdrouet/mrml?tab=readme-ov-file#missing-implementations
Dependencies
- Python >= 3.10
- Django >= 4.2
- mrml == 0.2.4
Installation
To install the package, run one of the following commands:
uv add django-mjml-email
pip install django-mjml-email
Configuration
To start using django-mjml-email, you must configure a mail backend in your settings. If you're
using SMTP to send your emails:
EMAIL_BACKEND = "django_mjml_email.backend.SMTPMJMLEmailBackend"
If you're using any other email backend, you should define your custom backend and then refer to it
in settings.py.
# yourproject/my_email_backend.py
from django.core.mail.backends.console import EmailBackend
from django_mjml_email.mjml_email import MJMLEmailMixin
class MyEmailBackend(MJMLEmailMixin, EmailBackend):
pass
# settings.py
# ...
EMAIL_BACKEND = "my_email_backend.MyEmailBackend"
Only Django builtin backends are supported, so if you're using AnyMail or any other email backend, please report any problem in the issues.
Usage
You can create email templates using MJML. For example, create a file named email_template.mjml:
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>
Welcome to our application!
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
In your Django code, you don't need anything special to send it:
from django.core.mail import send_mail
from django.template.loader import get_template
template = get_template("email_template.mjml")
send_mail(
"It works!",
template.render(),
"MJML Sender <from@example.com>",
["to@example.com"],
)
Running Tests
To run the tests, make sure you have installed the dev dependencies (e.g. via uv), then run
pytest:
uv run pytest
Alternatively, if you have activated your virtual environment with pytest installed:
pytest
Contributions
Contributions, bug reports, and suggestions are welcome! Feel free to open an issue or submit a pull request on Codeberg.
License
This project is distributed under the BSD 3-Clause Clear License. See the LICENSE file for
more details.
Metadata
Release files for django-mjml-email 0.2.1
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_mjml_email-0.2.1.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_mjml_email-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / django_mjml_email-0.2.1.tar.gz
| Download URL | django_mjml_email-0.2.1.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13734379d9a4116ebf86101ea229463a217dbffab0b8234eeb6cc6bd429c3bad
|
|
BLAKE2b-256 checksum How to use checksums |
e85de3661fccdc7155b61e15a815f430817d299d3dc1f9d38e90d3bc50f18c8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / django_mjml_email-0.2.1-py3-none-any.whl
| Download URL | django_mjml_email-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d5a0dc2450a5e72289472f0d35ed463a9973ac54f46a38b787a5a438c80a17c
|
|
BLAKE2b-256 checksum How to use checksums |
a6909c61231095c7b9e5919c35f0428c6bbeceae85cd7bee15e30ef3d7d95a94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|