Use mjml in your Django project
Project description
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 mjml-python.
The rust port is almost complete, it lacks a single feature: https://github.com/jdrouet/mrml?tab=readme-ov-file#missing-implementations
Requirements
- Python >= 3.12
- Django >= 4.2
- mjml-python == 1.3.5
Installation
To install the package, run the following command:
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 tested, 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"],
)
Contributions
Contributions, bug reports, and suggestions are welcome! Feel free to open an issue or submit a pull request.
License
This project is distributed under the BSD 3-Clause Clear License. See the
LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_mjml_email-0.1.0.tar.gz.
File metadata
- Download URL: django_mjml_email-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9d6ad355c53ff1b54f2b2e9df84fb563b7dcbd190cd5fc3d39a8400fa1c8abd
|
|
| MD5 |
bfe8406b62804eb83b7ea3dc79a47ddf
|
|
| BLAKE2b-256 |
662585303d1073fef0efdcbaf8d32d840cc03eb192c422231a8b3224f7239036
|
File details
Details for the file django_mjml_email-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_mjml_email-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bcb6ff0c9fab04339704ad2abc9798a18f9775ee4182960b123caa0e54661bd
|
|
| MD5 |
e5265ddb4839b1a52a2a0fc044adfcef
|
|
| BLAKE2b-256 |
9919ae993ffd1773c20c325a65e5964bddadbe9df00fa653a2ee9aab545ad3fe
|