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

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.

Development

make check  # ruff, and the tests
make build  # sdist and wheel in dist/

Metadata

Release files for django-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-lettermint 0.1.0
File Size Uploaded Provenance
django_lettermint-0.1.0.tar.gz 5.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 13.5 kB

Release files / django_lettermint-0.1.0.tar.gz

Download URL django_lettermint-0.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d5b8598b9040d89ff659511c1c34871d5aeab88da480718be90b72db7b87b61e
BLAKE2b-256 checksum
How to use checksums
a09c0fe72f7c080d7050cf1e0054379e416663f479ed8482a6026523a2163c1f
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.0-py3-none-any.whl

Download URL django_lettermint-0.1.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba03b93b393b0bdd28da2b5ff1e28433222924969fac73686819b75cf24027f7
BLAKE2b-256 checksum
How to use checksums
0334f8c7f4c29c64c54fb526b2f2265c9739641c8cd7dec0cfbd49f5adc11cb5
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.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.

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.

Release history Release notifications | RSS feed

This release

0.1.0 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