Skip to main content

django-anymail-lettermint

Lettermint (EU transactional email) support for django-anymail: an email backend plus tracking and inbound webhooks, written against Anymail's own base classes.

Your code uses Anymail's normalized API (anymail_status, metadata, tags, send_at, esp_extra, the tracking and inbound signals). Moving to or from another Anymail ESP is a settings change.

Install

pip install django-anymail-lettermint

Requires Python 3.10+, Django 5.2 / 6.0 / 6.1 and django-anymail 15.x. (Anymail 15 itself requires Django 5.0 or newer, so Django 4.2 is not supported.)

Settings

Django 6.1+ (MAILERS):

MAILERS = {
    "default": {
        "BACKEND": "anymail_lettermint.EmailBackend",
        "OPTIONS": {
            "api_token": env("LETTERMINT_API_TOKEN"),  # project sending token
            # "route": "outgoing",                     # default route slug
            # "api_url": "https://api.lettermint.co/v1/",
        },
    },
}

Django 6.0 and earlier (EMAIL_BACKEND):

EMAIL_BACKEND = "anymail_lettermint.EmailBackend"
ANYMAIL = {
    "LETTERMINT_API_TOKEN": env("LETTERMINT_API_TOKEN"),
    # "LETTERMINT_ROUTE": "outgoing",
}
Setting Required Meaning
LETTERMINT_API_TOKEN / api_token yes Project sending token (x-lettermint-token)
LETTERMINT_ROUTE / route no Route slug for every message; override with esp_extra={"route": ...}
LETTERMINT_API_URL / api_url no Defaults to https://api.lettermint.co/v1/
LETTERMINT_WEBHOOK_SECRET for tracking webhooks Signing secret (whsec_…) of the tracking webhook
LETTERMINT_INBOUND_SECRET for inbound webhooks Signing secret (whsec_…) of the inbound webhook

Sending

from anymail.message import AnymailMessage

msg = AnymailMessage(
    "Welcome",
    "Hi!",
    "Team <team@example.com>",
    ["user@example.com"],
    tags=["welcome"],
    metadata={"user_id": 42},
    esp_extra={
        "idempotency_key": f"welcome-{user.pk}",  # sent as the Idempotency-Key header
        "tags": [{"name": "plan", "value": "pro"}],  # Lettermint name/value tags
        "sandbox_result": "delivered",  # Sandbox projects only
    },
)
msg.send()
msg.anymail_status.message_id  # Lettermint message_id
msg.anymail_status.status  # {"queued"}: Lettermint answered "pending" or "scheduled"

merge_data={} sends one message per to recipient through POST /send/batch, with merge_metadata and merge_headers applied to each recipient.

Feature support

Anymail feature Lettermint Notes
from, to, cc, bcc, reply_to, subject ✅
Text and HTML body ✅ One HTML part only
Attachments ✅ Inline attachments need a Content-ID. Unnamed attachments get a filename like attachment.gif
Extra headers ✅ Values are sent as strings
metadata ✅ Values are sent as strings. Stored with the message and returned in webhooks; not added as email headers
tags ⚠️ one tag Maps to Lettermint's single tag; more than one raises AnymailUnsupportedFeature
Name/value tags via esp_extra esp_extra={"tags": [{"name": ..., "value": ...}]}
track_opens, track_clicks ✅ Per-message settings override of the route
send_at ✅ scheduled_at
Batch send (merge_data={}) ✅ POST /send/batch, one message per to
merge_metadata, merge_headers ✅ Batch send only
template_id, merge_data values, merge_global_data ❌ Lettermint has no stored templates
envelope_sender ❌
Route, TLS policy, sandbox result via esp_extra route, settings={"tls": "enforced"}, sandbox_result
Idempotency via esp_extra idempotency_key becomes the Idempotency-Key header. For a batch it covers the whole request
Tracking webhook ✅ Signed (HMAC-SHA256)
Inbound webhook ✅ Signed (HMAC-SHA256)

Lettermint's API has no stored templates (so no template_id or merge variables), and it sets the envelope sender (Return-Path) per domain in DNS, not per message. For personalized email, render each body in Django and send one message per recipient:

from django.template.loader import render_to_string

for user in users:
    context = {"user": user}
    AnymailMessage(
        render_to_string("welcome/subject.txt", context).strip(),
        render_to_string("welcome/body.txt", context),
        to=[user.email],
        metadata={"user_id": user.pk},
    ).send()

Unsupported features raise AnymailUnsupportedFeature unless you set ANYMAIL["IGNORE_UNSUPPORTED_FEATURES"] = True.

Webhooks

# urls.py
urlpatterns = [
    path("anymail/", include("anymail_lettermint.urls")),
]

This adds:

  • https://yoursite.example/anymail/lettermint/tracking/ for message.* status events
  • https://yoursite.example/anymail/lettermint/inbound/ for message.inbound

In the Lettermint dashboard, create one webhook for each URL. Copy each webhook's signing secret into LETTERMINT_WEBHOOK_SECRET (tracking) or LETTERMINT_INBOUND_SECRET (inbound). Each view checks X-Lettermint-Signature (HMAC-SHA256 over "<t>." + body, compared in constant time). It also requires X-Lettermint-Delivery to equal the signed timestamp and the timestamp to be within 5 minutes. Anything else gets HTTP 400 and no signal fires. If you also set Anymail's shared WEBHOOK_SECRET, basic auth is enforced as well.

Then handle Anymail's standard signals:

from anymail.signals import inbound, tracking
from django.dispatch import receiver


@receiver(tracking)
def handle_tracking(sender, event, esp_name, **kwargs):
    if event.event_type == "bounced":
        ...  # event.recipient, event.message_id, event.mta_response, event.metadata


@receiver(inbound)
def handle_inbound(sender, event, esp_name, **kwargs):
    message = event.message  # AnymailInboundMessage
    message.envelope_recipient  # Lettermint's data.recipient: route on this

Event mapping

Lettermint event Anymail event_type reject_reason
message.created, message.scheduled queued
message.sent sent
message.delivered delivered
message.auto_replied autoresponded
message.hard_bounced bounced bounced
message.soft_bounced deferred
message.spam_complaint complained spam
message.failed failed other
message.suppressed rejected blocked
message.policy_rejected rejected spam
message.unsubscribed unsubscribed unsubscribed
message.opened opened
message.clicked clicked
anything else (message.canceled, suppression.*, webhook.test, …) unknown

Every event carries event_id (Lettermint's delivery id, which stays the same on retries, so use it to de-duplicate), timestamp, message_id, recipient, metadata, tags (the single tag), description (reason), mta_response (response.content), click_url (destination_url), user_agent, and the raw payload as esp_event. message.created covers every recipient, so its recipient is None. For message.auto_replied, recipient is the auto-reply's sender (data.auto_reply.sender).

Inbound attachments that Lettermint sends as a download URL instead of inline content are fetched while the webhook request is being handled.

How this differs from other Lettermint packages

Package Built on Notes
django-anymail-lettermint (this) django-anymail Anymail's message API, anymail_status, tracking/inbound signals; no Lettermint SDK needed
django-lettermint Lettermint Python SDK Plain Django email backend; Django 6.1+
lettermint-django Lettermint Python SDK Plain Django email backend

Pick this one if you already use Anymail, or want to be able to switch ESPs without code changes.

Upstreaming

The goal is to merge this into django-anymail itself. Under Anymail's policy for new ESPs, that requires a "new ESP request" issue that collects enough community interest. If you want Lettermint in Anymail, 👍 that issue. The backend and webhook modules here mirror Anymail's own layout so they can move upstream largely unchanged.

Development

uv sync
uv run pytest --cov          # unit tests, ≥95% coverage enforced
uv run ruff check . && uv run ruff format --check . && uv run mypy
uv run tox -p auto           # Python 3.10–3.14 × Django 5.2/6.0/6.1, plus lowest Anymail

Live test against a Lettermint Sandbox project (skipped without a token):

LETTERMINT_TEST_TOKEN=... LETTERMINT_TEST_FROM=you@verified-domain uv run pytest -m live

License

BSD-3-Clause, the same as django-anymail.

Metadata

Release files for django-anymail-lettermint 0.1.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-anymail-lettermint 0.1.0
File Size Uploaded Provenance Actions
django_anymail_lettermint-0.1.0.tar.gz 21.5 kB With provenance Details for django_anymail_lettermint-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-anymail-lettermint 0.1.0
File Interpreter ABI Platform Actions
django_anymail_lettermint-0.1.0-py3-none-any.whl Python 3 none any Details for django_anymail_lettermint-0.1.0-py3-none-any.whl

Total release size: 36.1 kB

Release files / django_anymail_lettermint-0.1.0.tar.gz

Download URL django_anymail_lettermint-0.1.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ec1a777c3827e7ba9354bc8d8cb47905073b29327fc5ee1713aa6d0400a49d05
BLAKE2b-256 checksum
How to use checksums
58cc778feb1337f4b003fee3b14767bb3eebf1be741a612afda1b0dcd917b63f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 25, 2026.

Transparency log

Release files / django_anymail_lettermint-0.1.0-py3-none-any.whl

Download URL django_anymail_lettermint-0.1.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eaa7990ecf290b5e26058902c4bd83d91abf42f7e1416b0dc5f78552d4fd1032
BLAKE2b-256 checksum
How to use checksums
76f17231c5c8a97e3afc01d43bf7c75b8d4e77364e2a1a9fc309263439aa0a4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 25, 2026.

Transparency log

Security for django-anymail-lettermint 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_anymail_lettermint-0.1.0.tar.gz

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 Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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