Skip to main content

Django eMark↓

emark logo: envelope with markdown stamp

Markdown template based HTML and text emails for Django.

  • simple email templates with markdown
  • support for HTML and text emails
  • i18n support
  • built-in UTM tracking
  • built-in sent, open and click tracking
  • automatic CSS inliner via premailer

PyPi Version Test Coverage GitHub License

Setup

python3 -m pip install emark
# settings.py
INSTALLED_APPS = [
    "emark",
    # ...
]
python3 manage.py migrate

Usage

<!-- myapp/my_message.md -->
# Hello World

Hi {{ user.short_name }}!
# myapp/emails.py
from emark.message import MarkdownEmail


class MyMessage(MarkdownEmail):
    subject = "Hello World"
    template_name = "myapp/my_message.md"
# myapp/views.py
from . import emails


def my_view(request):
    message = emails.MyMessage.to_user(request.user)
    message.send()

Templates

You can use Django's template engine, just like you usually would. You can use translations, template tags, filters, blocks, etc.

You may also have a base template, that you inherit form in your individual emails to provide a consistent salutation and farewell.

<!-- base.md -->
{% load static i18n %}
{% block salutation %}Hi {{ user.short_name }}!{% endblock %}

{% block content %}{% endblock %}

{% block farewell %}
{% blocktrans trimmed %}
Best regards,
{{ site_admin }}
{% endblocktrans %}
{% endblock %}

{% block footer %}
Legal footer.
{% endblock %}
<!-- myapp/email.md -->
{% extends "base.md" %}

{% block content %}
This is the content of the email.
{% endblock %}

Context

The context is passed to the template as a dictionary. Furthermore, you may override the get_context_data method to add additional context variables.

# myapp/emails.py
from emark.message import MarkdownEmail


class MyMessage(MarkdownEmail):
    subject = "Hello World"
    template_name = "myapp/email.md"

    def get_context_data(self):
        context = super().get_context_data()
        context["my_variable"] = "Hello World"
        return context

Tracking

Sent, Open & Click Tracking

Django eMark comes with built-in tracking for sent, open and click events. The tracking is done via a tracking pixel and a redirect view.

As an added bonus, this feature also comes with an open-in-browser link that allows the user to view the email in their browser if their email client does not support HTML emails.

This feature is disabled by default. To enable it, you need to use a separate email backend. This backend will send the email via SMTP and also add the tracking pixel and redirect view. However, it will send a separate email for each recipient, which may not be desirable in all cases.

# settings.py (Django 6.1+)
MAILERS = {
    "default": {
        "BACKEND": "emark.backends.TrackingSMTPEmailBackend",
        "OPTIONS": {"host": "smtp.example.com"},
    }
}

Furthermore, you need to add the tracking view to your urls.py:

# urls.py
from django.urls import include, path

urlpatterns = [
    # … other urls
    path("emark/", include("emark.urls")),
]

You will need to provide a domain name for the tracking pixel and redirect view. This can be done via the DOMAIN setting:

# settings.py
EMARK = {"DOMAIN": "example.com"}

If the site framework is installed and no settings are provided, the domain will be automatically set to the current site's domain.

The tracking data is stored in the database. You need to run migrations to create the necessary tables:

python3 manage.py migrate

You can analyze the tracking data via the tables emark_sent, emark_open and emark_click.

UTM Tracking

Every MarkdownEmail subclass comes with automatic UTM tracking. UTM parameters are added to all links in the email. Existing UTM params on link that have been explicitly set, are not overridden. The default parameters are:

  • utm_source: website
  • utm_medium: email
  • utm_campaign: {{ EMAIL_CLASS_NAME }}

The global UTM parameters can be overridden via the EMARK_UTM_PARAMS setting, which is a dictionary of parameters:

# settings.py
EMARK = {
    "UTM_PARAMS": {
        "utm_source": "website",  # default
        "utm_medium": "email",  # default
    }
}

You may also change the UTM parameters by overriding the get_utm_params or passing a utm_params dictionary to class constructor.

# myapp/emails.py
from emark.message import MarkdownEmail


class MyMessage(MarkdownEmail):
    subject = "Hello World"
    template_name = "myapp/email.md"

    # override the parameters for this email class
    def get_utm_params(self):
        return {
            "utm_source": "myapp",
            "utm_medium": "email",
            "utm_campaign": "my-campaign",
        }


# or alternatively during instantiation
MyMessage(utm_params={"utm_campaign": "my-other-campaign"}).send()

Development

Pretty HTML emails are great, unless they spam your console during development. To prevent this, you can use the ConsoleEmailBackend:

# settings.py (Django 6.1+)
MAILERS = {
    "default": {
        "BACKEND": "emark.backends.ConsoleEmailBackend",
    }
}

The ConsoleEmailBackend will only print the plain text version of the email.

Email Dashboard

Django eMark comes with a simple email dashboard to preview your templates.

To enable the dashboard, add the app to your INSTALLED_APPS setting

# settings.py
INSTALLED_APPS = [
    # ...
    "emark",
    "emark.contrib.dashboard",  # needs to be added before Django's admin app
    # ...
    "django.contrib.admin",  # required for the dashboard
    # ...
]

and add the following to your urls.py:

# urls.py
from django.urls import include, path


urlpatterns = [
    # … other urls
    path(
        "emark/",
        include(
            [
                path("", include("emark.urls")),
                path("dashboard/", include("emark.contrib.dashboard.urls")),
            ]
        ),
    ),
]

Next you need to register the email classes you want to preview in the dashboard:

# myapp/emails.py
from emark.message import MarkdownEmail
from emark.contrib import dashboard


@dashboard.register
class MyMessage(MarkdownEmail):
    subject = "Hello World"
    template_name = "myapp/email.md"

Credits

Metadata

Release files for emark 2.3.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 emark 2.3.0
File Size Uploaded
emark-2.3.0.tar.gz 21.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for emark 2.3.0
File Interpreter ABI Platform
emark-2.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.7 kB

Release files / emark-2.3.0.tar.gz

Download URL emark-2.3.0.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
99143cce34df753e560eaea8e47dfd24ff43899e33d5099d35466361b67b2879
BLAKE2b-256 checksum
How to use checksums
5465cb87b78623698900cfdf2fdf71e685d8b531034fe6809430acfad0f25f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log

Release files / emark-2.3.0-py3-none-any.whl

Download URL emark-2.3.0-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
399c420f779f252cafa9948a61aaa43d16732d89b2edee27d03daaaaa82485dc
BLAKE2b-256 checksum
How to use checksums
682f1bf8619d076e8f9abf677dd1fcf36649e161d80d6f83d7664f034f31af28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log
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