All Projects → azavea → Django Amazon Ses

azavea / Django Amazon Ses

Licence: apache-2.0
A Django email backend that uses Boto3 to interact with Amazon Simple Email Service (SES).

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Amazon Ses

Django Init
Project template used at Fueled for scaffolding new Django based projects. 💫
Stars: ✭ 126 (+63.64%)
Mutual labels:  aws, django
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (+516.88%)
Mutual labels:  aws, django
0x4447 product s3 email
📫 A serverless email server on AWS using S3 and SES
Stars: ✭ 2,905 (+3672.73%)
Mutual labels:  aws, email
Django Mail Templated
Send emails using Django template system
Stars: ✭ 146 (+89.61%)
Mutual labels:  django, email
Django S3 Like Storage
Your Own Amazon S3 Django Storage
Stars: ✭ 28 (-63.64%)
Mutual labels:  aws, django
Modoboa
Mail hosting made simple
Stars: ✭ 1,998 (+2494.81%)
Mutual labels:  django, email
Serverless Node Simple Messaging
Simple email AWS lambda function
Stars: ✭ 75 (-2.6%)
Mutual labels:  aws, email
Cookiecutter Django Vue Graphql Aws
A highly opinionated Cookiecutter template that fuses together Django, Vue.js, GraphQL, and AWS into one full-stack web application.
Stars: ✭ 213 (+176.62%)
Mutual labels:  aws, django
Hawkpost
Generate links that users can use to submit messages encrypted with your public key.
Stars: ✭ 843 (+994.81%)
Mutual labels:  django, email
Django Email Confirm La
Django email confirmation for any model and any field
Stars: ✭ 23 (-70.13%)
Mutual labels:  django, email
Django mail admin
The one and only django app to receive & send mail with templates and multiple configurations.
Stars: ✭ 140 (+81.82%)
Mutual labels:  django, email
Yesterday I Learned
Brainfarts are caused by the rupturing of the cerebral sphincter.
Stars: ✭ 50 (-35.06%)
Mutual labels:  aws, django
Django Notifs
Modular Notifications (InApp, Email, SMS, CustomBackend etc) for Django
Stars: ✭ 105 (+36.36%)
Mutual labels:  django, email
Django Herald
A Django messaging library
Stars: ✭ 159 (+106.49%)
Mutual labels:  django, email
Python Sparkpost
SparkPost client library for Python
Stars: ✭ 87 (+12.99%)
Mutual labels:  django, email
Django S3direct
Directly upload files to S3 compatible services with Django.
Stars: ✭ 570 (+640.26%)
Mutual labels:  aws, django
Simple S3 Setup
Code examples used in the post "How to Setup Amazon S3 in a Django Project"
Stars: ✭ 46 (-40.26%)
Mutual labels:  aws, django
Django Anymail
Django email backends and webhooks for Amazon SES, Mailgun, Mailjet, Postmark, SendGrid, Sendinblue, SparkPost and more
Stars: ✭ 1,109 (+1340.26%)
Mutual labels:  django, email
Waveboxapp
Wavebox Classic has been updated to Wavebox 10. Learn more Wavebox.io
Stars: ✭ 1,198 (+1455.84%)
Mutual labels:  email
Vaquarkhan
Stars: ✭ 1,199 (+1457.14%)
Mutual labels:  aws

django-amazon-ses

.. image:: https://github.com/azavea/django-amazon-ses/workflows/CI/badge.svg :target: https://github.com/azavea/django-amazon-ses/actions?query=workflow%3ACI .. image:: https://api.codeclimate.com/v1/badges/b69dce91215b7003066b/maintainability :target: https://codeclimate.com/github/azavea/django-amazon-ses/maintainability .. image:: https://api.codeclimate.com/v1/badges/b69dce91215b7003066b/test_coverage :target: https://codeclimate.com/github/azavea/django-amazon-ses/test_coverage

A Django email backend that uses Boto 3 <https://boto3.readthedocs.io/en/latest/>_ to interact with Amazon Simple Email Service (SES) <https://aws.amazon.com/ses/>_.

Table of Contents

  • Installation <#installation>_

  • AWS Credential Setup <#aws-credential-setup>_

    • AWS Named Profile <#aws-named-profile>_
    • AWS EC2 Instance Profile <#aws-ec2-instance-profile>_
  • Django Configuration <#django-configuration>_

  • Usage <#usage>_

  • Signals <#signals>_

    • pre_send <#pre-send>_
    • post_send <#post-send>_
  • Testing <#testing>_

Installation

First, install the Django Amazon SES email backend:

.. code:: bash

$ 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 Credential Setup

AWS Named Profile


Create an AWS API credential profile named test using the AWS CLI <https://aws.amazon.com/cli/>_:

.. code:: bash

$ aws --profile test configure

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

.. code:: bash

$ AWS_PROFILE="test" gunicorn my:app

AWS EC2 Instance Profile


Create an instance profile <http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-create-iam-instance-profile.html>_ 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:

.. code:: javascript

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

Django Configuration

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

.. code:: python

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.

.. code:: python

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'):

.. code:: python

AWS_DEFAULT_REGION = 'eu-west-1'

Alternatively, provide AWS credentials using the settings below. This is useful in situations where you want to use separate credentials to send emails via SES than you would for other AWS services.

.. code:: python

AWS_SES_ACCESS_KEY_ID = 'my_access_key...'
AWS_SES_SECRET_ACCESS_KEY = 'my_secret...'
AWS_SES_REGION = 'us-west-2'

If you want to force the use of a SES configuration set you can set the option below. This is useful when you want to do more detailed tracking of your emails such as opens and clicks. You can see more details at: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-configuration-sets.html.

.. code:: python

AWS_SES_CONFIGURATION_SET_NAME = 'my_configuration_set'

Usage

Once the configuration above is complete, use send_email to send email messages with Amazon SES from within your application:

.. code:: python

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
)

Signals

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.

pre_send


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:

.. code:: python

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

@receiver(pre_send)
def remove_blacklisted_emails(sender, message=None, **kwargs):
    blacklisted_emails = Blacklisted.objects.values_list('email', flat)
    message.to = [email for email in message.to 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.

post_send


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.

.. code:: python

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

from django_amazon_ses import post_send

@receiver(post_send)
def log_message(sender, message=None, message_id=None, **kwargs):
    SentMessage.objects.create(
        subject = message.subject,
        body = message.body,
        message_id = message_id,
        date_sent = timezone.now()
    )

Testing

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:

.. code:: bash

$ tox

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].