Skip to main content

Django email backend for AWS SES (Amazon Simple Email Service) without boto3

Project description

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 TXT and HTML emails.
  • Lightweight and easy to integrate.
  • Supports EmailMessage from Django's built-in mail framework.
  • Custom SES client implementation for signing and sending requests.

Requirements

  • Python 3.11+
  • Django 4.2+

Installation

Install the package using pip:

pip install django-ses-backend

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 create 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'

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()

Advanced Features

Sending HTML Emails

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

Error Handling

If sending an email fails, a SESClientError is raised. You can handle errors gracefully:

try:
    email.send()
except Exception 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

  • Ensure your AWS SES account is verified and out of sandbox mode to send emails to unverified addresses.
  • Configure AWS IAM policies to grant ses:SendEmail permissions to your credentials.

Contributing

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


This documentation provides a clear, structured, and practical guide for using django-ses-backend. Let me know if you need any refinements!

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_ses_backend-0.0.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

django_ses_backend-0.0.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file django_ses_backend-0.0.2.tar.gz.

File metadata

  • Download URL: django_ses_backend-0.0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.8 Darwin/24.3.0

File hashes

Hashes for django_ses_backend-0.0.2.tar.gz
Algorithm Hash digest
SHA256 061c59d46579d29d50e60beb8792790d04e14fdff792fd8d75bf9b91f65e247f
MD5 62ec36a05c11286bd3bebfcf135fc021
BLAKE2b-256 83ed603fff928ad6d275a8dc11b15b564d828606c9ce73e0cea3d7e3d0f61189

See more details on using hashes here.

File details

Details for the file django_ses_backend-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_ses_backend-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.8 Darwin/24.3.0

File hashes

Hashes for django_ses_backend-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94f6bb526a35f38f1959b99381acd9e0019a48735156fcc213a367afe325afe8
MD5 fa23526cfee6fc3ed4e4f3623dd9a88f
BLAKE2b-256 69416e02cb896e31dfef267d5aa2f96aaa005ce6ab12067b54879785b06e23cd

See more details on using hashes here.

Supported by

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