Amazon SES with Python and Django

Send via SES from Python? Check.

Advertisements

It’s amazing to see that a product that Amazon announces has ready-to-use python code overnight. Getting setup to send email using Amazon’s Simple Email Service is a breeze using Harry Marr’s [1] boto and Django-SES packages available on github [2][3].

Using SES directly in python is a matter of instantiating an SESConnection and calling send_email:


from boto.ses import SESConnection

source = "from@example.com"
subject = "hello SES!"
body = "email message from python!"
to_addresses = ["to@example.com"]

connection = SESConnection(aws_access_key_id=<your id>, aws_secret_access_key=<your key>)
connection.send_email(source, subject, body, to_addresses)

Integrating it into django is pretty trivial, just add to settings.py:


EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = <your id>
AWS_SECRET_ACCESS_KEY = <your key>

Once that’s in your settings, your application doesn’t have to change at all to send via SES.

The downside: SES does not handle attachments, period. You can only send text or HTML-formatted emails. If you need to send files, you’re out of luck for now.

Resources:
[1] http://hmarr.com/2011/jan/26/using-amazons-simple-email-service-ses-with-django/
[2] https://github.com/hmarr/boto
[3] https://github.com/hmarr/django-ses

3 thoughts on “Amazon SES with Python and Django”

  1. The Python community is an exciting place to be at this time and boto is a very nice example of open source done right (and Pythonic). Thank you for the helpful article!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s