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
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
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. 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_aws_mail-1.0.1.tar.gz.
File metadata
- Download URL: django_aws_mail-1.0.1.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2a8862932613db22f89881027dd9645f6b8de80041e1f7f4d84d8bf57779ebd
|
|
| MD5 |
2f20570c0d370e47d61c5dccb1366e38
|
|
| BLAKE2b-256 |
9d9e4d004b093f444f9e5b7412d79e1eb004121d2f509c53c7b2f01303f216c7
|
Provenance
The following attestation bundles were made for django_aws_mail-1.0.1.tar.gz:
Publisher:
publish.yml on django-aws-mail/django-aws-mail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_aws_mail-1.0.1.tar.gz -
Subject digest:
c2a8862932613db22f89881027dd9645f6b8de80041e1f7f4d84d8bf57779ebd - Sigstore transparency entry: 1096090592
- Sigstore integration time:
-
Permalink:
django-aws-mail/django-aws-mail@d9d8f8f80df05a30bd663d98e604b4c5bd21d412 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/django-aws-mail
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d9d8f8f80df05a30bd663d98e604b4c5bd21d412 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_aws_mail-1.0.1-py3-none-any.whl.
File metadata
- Download URL: django_aws_mail-1.0.1-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dc21e12c4579c9fa01fb5cb1206b24bb0c93c64235ad16976045da4ff6e96be
|
|
| MD5 |
7e5abe25114f7bf8fe127c20414350fc
|
|
| BLAKE2b-256 |
2a2c08265ae388eb1974ec1456b93fc72a11c8fd10fe485182f68a922242cc0c
|
Provenance
The following attestation bundles were made for django_aws_mail-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on django-aws-mail/django-aws-mail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_aws_mail-1.0.1-py3-none-any.whl -
Subject digest:
4dc21e12c4579c9fa01fb5cb1206b24bb0c93c64235ad16976045da4ff6e96be - Sigstore transparency entry: 1096090599
- Sigstore integration time:
-
Permalink:
django-aws-mail/django-aws-mail@d9d8f8f80df05a30bd663d98e604b4c5bd21d412 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/django-aws-mail
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d9d8f8f80df05a30bd663d98e604b4c5bd21d412 -
Trigger Event:
push
-
Statement type: