Django SES Email Backend

4.7.2 · active · verified Sat Apr 11

django-ses is a Django email backend that integrates with Amazon's Simple Email Service (SES), offering a reliable and scalable way to send emails. It acts as a drop-in replacement for Django's default email backend, routing emails through AWS SES instead of traditional SMTP. The library, currently at version 4.7.2, is actively maintained with frequent releases to support new Django and Python versions, address bugs, and introduce new features like bounce/complaint handling and email receiving capabilities.

Warnings

Install

Imports

Quickstart

Configure your Django `settings.py` to use `django_ses.SESBackend` and set your AWS credentials and region. It is highly recommended to manage `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SES_REGION_NAME` via environment variables or IAM roles for security. Ensure `DEFAULT_FROM_EMAIL` is set to an address or domain verified in AWS SES. Then, use Django's standard `send_mail` function to send emails.

import os
from django.core.mail import send_mail

# Ensure these are set in your Django settings.py
# EMAIL_BACKEND = 'django_ses.SESBackend'
# AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
# AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
# AWS_SES_REGION_NAME = os.environ.get('AWS_SES_REGION_NAME', 'us-east-1')
# DEFAULT_FROM_EMAIL = 'verified-sender@example.com'

# Example of sending a simple email
if os.environ.get('AWS_ACCESS_KEY_ID') and os.environ.get('AWS_SECRET_ACCESS_KEY'):
    try:
        send_mail(
            'Subject here',
            'Here is the message body.',
            os.environ.get('DEFAULT_FROM_EMAIL', 'test@example.com'),
            ['recipient@example.com'],
            fail_silently=False,
        )
        print("Email sent successfully!")
    except Exception as e:
        print(f"Failed to send email: {e}")
else:
    print("AWS credentials not set in environment variables. Cannot send email.")

view raw JSON →