Skip to main content

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"],
)

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.

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.0

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

Source distribution (sdist)

Source distribution for django-mjml-email 0.2.0
File Size Uploaded
django_mjml_email-0.2.0.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-mjml-email 0.2.0
File Interpreter ABI Platform
django_mjml_email-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / django_mjml_email-0.2.0.tar.gz

Download URL django_mjml_email-0.2.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4570c0c2cb0ebfb8a1df4411c916f67dc46f846bf26b0e6a86b210eb25141716
BLAKE2b-256 checksum
How to use checksums
c595e6e58aba013389da7f140ee77bece49c3ccd4c5457672362f4a839c1d7a6
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.0-py3-none-any.whl

Download URL django_mjml_email-0.2.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edc36bd99e8e74e564abe7f9cd3ea16edb903501276d8ad0ab056994657ddf78
BLAKE2b-256 checksum
How to use checksums
763e98a74da70b3c8c15f1f3951f3a229451fcdd1040c2b9f65afce8ae48daaa
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 history Release notifications | RSS feed

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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