Skip to main content

django-ses-backend

Django AWS SES (Amazon Simple Email Service) email backend.

Features

  • Send emails via AWS SES without needing boto3 or any other AWS SDK.
  • No SMTP configuration required and faster email sending.
  • Supports sending plain text and HTML emails, including multi-part messages.
  • Lightweight and easy to integrate.
  • Supports Django's EmailMessage and EmailMultiAlternatives.
  • Handles Reply-To and custom headers.
  • Custom SES client implementation with AWS signature v4, rate-limit retries, and exponential backoff.
  • Context manager support for use with with SESEmailBackend() as connection:.

Requirements

  • Python 3.11+
  • Django 4.2+

Installation

Install the package using pip:

pip install django-ses-backend

PyPi.com

AWS Setup

Step 1: Create an AWS SES Account

  1. Sign in to the AWS Management Console.
  2. Navigate to Amazon SES service.
  3. Verify your email address or domain in the Verified Identities section.
  4. Move your SES account out of Sandbox Mode (if needed) by requesting production access.

Step 2: Create an IAM User for SES

  1. Go to IAM in the AWS Console.
  2. Create a new user and enable Programmatic access.
  3. Attach the policy AmazonSESFullAccess (or a custom policy with ses:SendEmail permissions).
  4. Save the Access Key ID and Secret Access Key.

Configuration

Update your Django settings:

# settings.py
EMAIL_BACKEND = 'django_ses_backend.backends.SESEmailBackend'

SES_AWS_ACCESS_KEY_ID = 'YOUR_AWS_ACCESS_KEY_ID'
SES_AWS_SECRET_ACCESS_KEY = 'YOUR_AWS_SECRET_ACCESS_KEY'
SES_AWS_REGION = 'YOUR_AWS_REGION'

# Optional advanced settings
SES_ENDPOINT_URL = None           # Custom endpoint URL
SES_ENDPOINT_PATH = None          # Custom endpoint path
SES_TIMEOUT = 10                  # HTTP request timeout in seconds
SES_MAX_RETRIES = 3               # Max retry attempts for rate-limits/server errors
SES_RETRY_DELAY = 1.0             # Base delay (seconds) for exponential backoff

Usage

You can send emails using Django's built-in send_mail or EmailMessage:

from django.core.mail import send_mail

send_mail(
    subject="Hello from AWS SES",
    message="This is a test email.",
    from_email="your-email@example.com",
    recipient_list=["recipient@example.com"],
)

Or using EmailMessage for more customization:

from django.core.mail import EmailMessage

email = EmailMessage(
    subject="Hello from AWS SES",
    body="This is a test email.",
    from_email="your-email@example.com",
    to=["recipient@example.com"],
)
email.send()

Sending HTML Emails

Supports both HTML and text content:

from django.core.mail import EmailMultiAlternatives

email = EmailMultiAlternatives(
    subject="HTML Email Test",
    body="Fallback plain text content",
    from_email="your-email@example.com",
    to=["recipient@example.com"],
)
email.attach_alternative("<h1>Hello from AWS SES</h1>", "text/html")
email.send()

Handling Reply-To and Custom Headers

email = EmailMessage(
    subject="Email with Reply-To",
    body="Hello",
    from_email="your-email@example.com",
    to=["recipient@example.com"],
    reply_to=["replyto@example.com"],
    headers={"Message-ID": "<custom.id@example.com>"},
)
email.send()

Error Handling

  • SESClientError is raised for generic sending failures.
  • SESRatelimitError is raised when AWS rate-limits are hit.
  • Retries are performed automatically with exponential backoff for 429/5xx errors.
try:
    email.send()
except SESClientError as e:
    print(f"Failed to send email: {e}")

Logging

Enable logging to track email sending:

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("django_ses_backend")

Notes

  • Always include both text and HTML versions for best deliverability.
  • Attachments are ignored by this backend.
  • Ensure your AWS SES account is verified and out of sandbox mode.
  • Configure AWS IAM policies to grant ses:SendEmail permissions.

Contributing

Feel free to submit issues or pull requests on GitHub to improve this package.

Release files for django-ses-backend 0.1.3

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-ses-backend 0.1.3
File Size Uploaded
django_ses_backend-0.1.3.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-ses-backend 0.1.3
File Interpreter ABI Platform
django_ses_backend-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / django_ses_backend-0.1.3.tar.gz

Download URL django_ses_backend-0.1.3.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4a01e203db46f8429f6692f7025d2b1816187c6f0682175182f350e2959bb2f7
BLAKE2b-256 checksum
How to use checksums
230298d6921848ec6ab42621fecc87b6ef6ffc806218029bbf1eb54cb79cfbe9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.13.7 Darwin/24.6.0

Release files / django_ses_backend-0.1.3-py3-none-any.whl

Download URL django_ses_backend-0.1.3-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b27cabbbc97741bfea49a6ed41d504ca835f8b682dda93c57a5f104dd065e1c
BLAKE2b-256 checksum
How to use checksums
c2660edd99568c96acfe5e0640f32bb0f79bb6f5d53bde000874e5a24eef54a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.13.7 Darwin/24.6.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.2

2 release files

0.0.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