Skip to main content

AWS mail for Django using SES and SNS.

Project description

A Django email backend for Amazon’s Simple Email Service (SES) v2 and utility views + signals for Amazon’s Simple Notification Service (SNS).

Author:

Bas van Gaalen (http://github.com/webtweakers)

License:

MIT

https://img.shields.io/pypi/v/django-aws-mail.svg

Features

  • Fully compatible with Django 6.0+ (Modern Python Email API).

  • Supports AWS SESv2 (via boto3).

  • Integrated with AWS SNS for bounce and complaint handling.

  • Flexible configuration via Django settings or environment variables.

  • Comprehensive signal support for tracking email lifecycles.

Installation

Install the package via pip or poetry:

pip install django-aws-mail

Configuration

Add the backend to your Django settings.py:

EMAIL_BACKEND = 'django_aws_mail.backends.EmailBackend'

Usage

The library provides a compose utility to easily create multipart emails (HTML and Text) using Django templates.

from django_aws_mail.utils import compose

# Create the message
message = compose(
    recipients=["customer@example.com"],
    subject="Welcome to our service!",
    template="email/welcome.html",
    context={"name": "John Doe"},
    from_email="Support <support@example.com>"
)

# Send it
message.send()

Signals

The library provides a rich set of signals to track the lifecycle of your emails.

Backend Signals

These fire during the .send() process within your application:

  • mail_pre_send: Fired before the message is sent to AWS.

  • mail_post_send: Fired after a successful API response from AWS.

SNS Webhook Signals

These are triggered by AWS SNS notifications (via the provided webhook views):

  • mail_send: The email was successfully sent by SES.

  • mail_delivery: The email was successfully delivered to the recipient.

  • mail_bounce: The email bounced (Hard or Soft).

  • mail_complaint: The recipient marked the email as spam.

  • mail_reject: SES rejected the email (e.g., due to virus or blacklisting).

  • mail_delivery_delay: There is a delay in delivering the email.

  • mail_open: The recipient opened the email (requires SES tracking).

  • mail_click: The recipient clicked a link (requires SES tracking).

Example Usage:

from django.dispatch import receiver
from django_aws_mail.signals import mail_bounce, mail_complaint

@receiver(mail_bounce)
def handle_bounce(sender, message_id, bounce_type, **kwargs):
    # Handle the bounce (e.g., deactivate the user's email)
    print(f"Email {message_id} bounced. Type: {bounce_type}")

Development

To run the sandbox management command:

poetry install
poetry run manage

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_aws_mail-0.4.5.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_aws_mail-0.4.5-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file django_aws_mail-0.4.5.tar.gz.

File metadata

  • Download URL: django_aws_mail-0.4.5.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_aws_mail-0.4.5.tar.gz
Algorithm Hash digest
SHA256 6323fcb074f0b9006891bb0f4faac45156f2b471e893a21d5c4c10611754798b
MD5 1a76dbb207394c9dbcd6aa9d9b12db45
BLAKE2b-256 977de95c6cd48e124fc5f77c4b6b35d5afded9f1b1657ab160abe719a888c264

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_aws_mail-0.4.5.tar.gz:

Publisher: publish.yml on django-aws-mail/django-aws-mail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_aws_mail-0.4.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_aws_mail-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a50c80f34b06dd7794eaf24b74973f81b3d09ea8d57d6381c8ebac367b6c8e74
MD5 8e6e2d7008b571c7900e6b1bd7d6a8f1
BLAKE2b-256 5edf9b98dea5bccb8a983165e914b2cdcc7eba782d09022dd38e4617d1cfec46

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_aws_mail-0.4.5-py3-none-any.whl:

Publisher: publish.yml on django-aws-mail/django-aws-mail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page