Skip to main content

Django-AWS-Mail

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'

Environment Variables

The library automatically detects the following environment variables (or Django settings). Copy example.env to .env to get started:

MAIL_AWS_REGION_NAME=eu-west-1
MAIL_AWS_ACCESS_KEY_ID=ABC123
MAIL_AWS_SECRET_ACCESS_KEY=S3cr3t

MAIL_AWS_SNS_TOPIC_ARN=arn:aws:sns:eu-west-1:123:abc
MAIL_AWS_SNS_VERIFY_NOTIFICATION=true
MAIL_AWS_SNS_VERIFY_CERTIFICATE=true

If you wish to have Boto3 search for credentials (as explained in Boto3’s Credentials documentation <https://docs.aws.amazon.com/boto3/latest/guide/credentials.html#configuring-credentials>), you can omit MAIL_AWS_ACCESS_KEY_ID and MAIL_AWS_SECRET_ACCESS_KEY:

MAIL_AWS_REGION_NAME=eu-west-1

MAIL_AWS_SNS_TOPIC_ARN=arn:aws:sns:eu-west-1:123:abc
MAIL_AWS_SNS_VERIFY_NOTIFICATION=true
MAIL_AWS_SNS_VERIFY_CERTIFICATE=true

Create your AWS ACCESS KEYS by logging in to the AWS Console. Then click your account name at the top right corner and select “Security credentials”. Then, in the left sidebar menu, below “Access Management”, select “Users” and click the button “Create user”. Afterwards, chose to create an access key.

Usage

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

from django_aws_mail.message 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. For more information on the contents of these notifications, see the AWS SES documentation.

  • 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).

Signal Example:

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

@receiver(mail_bounce)
def handle_bounce(sender, mail, event, message, **kwargs):
    # Retrieve info from the event dictionary
    bounce_type = event.get('bounceType')
    message_id = mail.get('messageId')

    print(f"Email {message_id} bounced. Type: {bounce_type}")

Development

To run the sandbox management command:

poetry install
poetry run manage

To run tests and get the coverage:

poetry run manage test django_aws_mail

poetry run coverage run sandbox/manage.py test django_aws_mail

poetry run coverage report

poetry run coverage html

Metadata

Release files for django-aws-mail 1.0.2

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-aws-mail 1.0.2
File Size Uploaded
django_aws_mail-1.0.2.tar.gz 32.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-aws-mail 1.0.2
File Interpreter ABI Platform
django_aws_mail-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 64.9 kB

Release files / django_aws_mail-1.0.2.tar.gz

Download URL django_aws_mail-1.0.2.tar.gz
Size 32.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5478fb13935cfd3cbc60a67c1d312d951fb20019c6456d9e73efd4546ae6080a
BLAKE2b-256 checksum
How to use checksums
14f26650e53134db1a59b1034f462d84acfb6ddc3fcb05af136259a0289f96c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.14.5 Darwin/25.6.0

Release files / django_aws_mail-1.0.2-py3-none-any.whl

Download URL django_aws_mail-1.0.2-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07a8e9570bdbab96ec2d96098e9912908a3da5a2e1eff9bbcdb117c8deab95bb
BLAKE2b-256 checksum
How to use checksums
9e95a4ea0afa207cbd3690fc85ec3efd4f6e6fd46da98c021c76d87ee44b16ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.14.5 Darwin/25.6.0

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3

2 release files

0.2

2 release files

0.1.2

2 release files

0.1.1

2 release files

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