Skip to main content

django-lettermint

A Django email backend that sends mail through Lettermint using the official lettermint Python SDK.

Supported versions

  • Django 6.1
  • Python 3.12, 3.13, 3.14

Other versions may work, but are not tested.

Configuration and Installation

pip install django-lettermint

Add "django_lettermint" to INSTALLED_APPS. Then configure it as a mailer in MAILERS.

MAILERS = {
    "default": {
        "BACKEND": "django_lettermint.backend.LettermintEmailBackend",
        "OPTIONS": {
            "sending_token": os.environ["LETTERMINT_SENDING_TOKEN"],
            "route": os.environ.get("LETTERMINT_ROUTE", ""),
        },
    },
}
Option Default Description
sending_token "" Project sending token (lm_…). Sending without it raises ImproperlyConfigured.
route "" Route slug to send through. When it is blank, the project's default route is used.
timeout SDK default (30) Optional. Request timeout in seconds, covering the whole request including the response body.

Lettermint-specific options per message

You can set these optional attributes on any EmailMessage:

message = EmailMultiAlternatives(subject, text, to=[user.email])
message.attach_alternative(html, "text/html")
message.lettermint_tags = {"campaign": "welcome"}  # name -> value
message.lettermint_metadata = {"user_id": str(user.pk)}
message.lettermint_route = "broadcast"  # overrides the route option
message.lettermint_idempotency_key = f"welcome-{user.pk}"
message.send()

message.lettermint_message_id  # "…", set after a successful send
message.lettermint_status  # "pending"

How a Django message is mapped

Django Lettermint
from_email, to, cc, bcc, reply_to, subject the same fields
body text, or html when content_subtype == "html"
text/html alternative html
extra_headers headers
attachments (tuples, MIMEPart, message/rfc822) attachments; the Content-ID becomes content_id

Handling failures

The backend doesn't support fail_silently, following Django's Replacing fail_silently advice. Every failure raises, so the caller decides what to ignore:

Exception When
ImproperlyConfigured The mailer has no sending_token.
lettermint.LettermintError The API rejected the message or the request failed, e.g. ValidationError, RateLimitError, APITimeoutError.
ValueError Django rejects the message (e.g. a newline in a header), or it can't be mapped to Lettermint (e.g. a non-HTML alternative or no to recipient).
from lettermint import LettermintError

try:
    message.send()
except LettermintError:
    logger.warning("Lettermint could not send %r", message.subject)

When one call sends several messages and one fails, the messages before it were already sent and have lettermint_message_id set.

Checking it works

  • manage.py check --deploy warns (lettermint.W001) when a Lettermint mailer has no sending_token.
  • manage.py check errors (lettermint.E001) on unknown OPTIONS, and on a sending_token or timeout the SDK rejects, such as a token with a trailing newline.
  • Send a real test email with manage.py sendtestemail you@example.com.

Limitations

  • A message needs at least one to recipient; Bcc-only messages raise ValueError.
  • One API request per message, sent synchronously. There is no batch sending (/send/batch) or background queue.
  • Only one HTML body and no other alternatives; a text/plain alternative next to an HTML body is rejected too.
  • No per-message scheduling, tracking settings or sandbox results.
  • No webhooks yet, so delivery events are visible only in the Lettermint dashboard.

Metadata

Release files for django-lettermint 0.1.1

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-lettermint 0.1.1
File Size Uploaded Provenance Actions
django_lettermint-0.1.1.tar.gz 5.8 kB Without provenance Details for django_lettermint-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 13.5 kB

Release files / django_lettermint-0.1.1.tar.gz

Download URL django_lettermint-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ce6ebe0f8321201e469a79e32586ce66efbe54a1062fa89beab6c6cd43781ffd
BLAKE2b-256 checksum
How to use checksums
c80589f46bcd79dd6a57cc98da271e0b4f501a2254664433184671147e260d69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / django_lettermint-0.1.1-py3-none-any.whl

Download URL django_lettermint-0.1.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68f64e05e32529130ffba585053c313648f63786296abccdb6d5dbe0988312c5
BLAKE2b-256 checksum
How to use checksums
0e3c24a911a633408891ad4c7ff6bd43bd8064bbbb3bfd90694a1f9fa55c3a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Security for django-lettermint 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.1 This release

2 release files No 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