Skip to main content

A Django email backend that uses Boto3 to interact withAmazon Simple Email Service (SES).

Project description

A Django email backend that uses Boto 3 to interact with Amazon Simple Email Service (SES).


First, install the Django Amazon SES email backend:

$ pip install django-amazon-ses

Next, ensure that your Amazon Web Services (AWS) API credentials are setup, or that you are running on an Amazon EC2 instance with an instance profile that has access to the Amazon SES service.

AWS API Credential Setup

Create an AWS API credential profile named test using the AWS CLI:

$ aws --profile test configure

Ensure that the AWS_PROFILE environment variable is set so that Boto 3 knows which credentials profile to use:

$ AWS_PROFILE="test" gunicorn my:app

AWS EC2 Instance Profile

Create an instance profile with at least the ses:SendRawEmail action. Then, associate it with the instance/s running your application. An example policy that enables access to the ses:SendRawEmail action is below:

   "Version": "2012-10-17",
   "Statement": [
         "Effect": "Allow",
         "Action": ["ses:SendRawEmail"],

Django Configuration

Lastly, override the EMAIL_BACKEND setting within your Django settings file:

EMAIL_BACKEND = 'django_amazon_ses.EmailBackend'

Optionally, you can set the AWS credentials. If unset, the backend will gracefully fall back to other Boto 3 credential providers.

AWS_ACCESS_KEY_ID = 'my_access_key...'
AWS_SECRET_ACCESS_KEY = 'my_secret...'

Optionally, you can set the AWS region to be used (default is 'us-east-1'):

AWS_DEFAULT_REGION = 'eu-west-1'


Two signals are provided for the backend, pre_send and post_send. Both signals receive the message object being sent. The post_send signal also receives the Amazon SES message ID of the sent message.


You can modify the email message on pre_send. For example, if you have a blacklist of email addresses that should never receive emails, you can filter them from the recipients:

from django.dispatch.dispatcher import receiver
from django_amazon_ses import pre_send

def remove_blacklisted_emails(sender, message=None, **kwargs):
    blacklisted_emails = Blacklisted.objects.values_list('email', flat) = [email for email in if email not in blacklisted_emails]

If the pre_send receiver function ends up removing all of the recipients from the message, the email is not processed and the post_send signal is not sent.


Similarly, the post_send signal can be used to log messages sent by the system. This is useful if you want to log the subject line of a message that bounced or received a complaint.

from django.dispatch.dispatcher import receiver
from django.utils import timezone

from django_amazon_ses import post_send

def log_message(sender, message=None, message_id=None, **kwargs):
        subject = message.subject,
        body = message.body,
        message_id = message_id,
        date_sent =


The test suite execution process is managed by tox and takes care to mock out the Boto 3 interactions with Amazon’s API, so there is no need for a valid set of credentials to execute it:

$ tox

Project details

Release history Release notifications

History Node


This version
History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_amazon_ses-1.0.0-py2.py3-none-any.whl (10.8 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Dec 7, 2017
django-amazon-ses-1.0.0.tar.gz (9.9 kB) Copy SHA256 hash SHA256 Source None Dec 7, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page