Attention: This project is not actively maintained as of ~end 2012, but it is still fairly popular and in use. If you are interested in helping out, please contact Paul Craciunoiu (pcraciunoiu).
Django-SES is a drop-in mail backend for Django. Instead of sending emails through a traditional SMTP mail server, Django-SES routes email through Amazon Web Services' excellent Simple Email Service (SES).
Amazon SES allows you to also setup usernames and passwords. If you do configure things that way, you do not need this package. The Django default email backend is capable of authenticating with Amazon SES and correctly sending email.
Using django-ses gives you additional features like deliverability reports that can be hard and/or cumbersome to obtain when using the SMTP interface.
Note: In order to use smtp with Amazon SES, you may have to install some supporting packages for ssl. Check out this SMTP SSL email backend for Django
Configuring, maintaining, and dealing with some complicated edge cases can be time-consuming. Sending emails with Django-SES might be attractive to you if:
You can do the following to install boto 2.1.0 (we're using --upgrade here to make sure you get 2.1.0):
pip install --upgrade boto
pip install django-ses
Add the following to your settings.py:
EMAIL_BACKEND = 'django_ses.SESBackend' # These are optional -- if they're set as environment variables they won't # need to be set here as well AWS_ACCESS_KEY_ID = 'YOUR-ACCESS-KEY-ID' AWS_SECRET_ACCESS_KEY = 'YOUR-SECRET-ACCESS-KEY' # Additionally, you can specify an optional region, like so: AWS_SES_REGION_NAME = 'us-east-1' AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
Alternatively, instead of AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, you can include the following two settings values. This is useful in situations where you would like to use a separate access key to send emails via SES than you would to upload files via S3:
AWS_SES_ACCESS_KEY_ID = 'YOUR-ACCESS-KEY-ID' AWS_SES_SECRET_ACCESS_KEY = 'YOUR-SECRET-ACCESS-KEY'
Now, when you use django.core.mail.send_mail, Simple Email Service will send the messages by default.
Since SES imposes a rate limit and will reject emails after the limit has been reached, django-ses will attempt to conform to the rate limit by querying the API for your current limit and then sending no more than that number of messages in a two-second period (which is half of the rate limit, just to be sure to stay clear of the limit). This is controlled by the following setting:
AWS_SES_AUTO_THROTTLE = 0.5 # (default; safety factor applied to rate limit)
To turn off automatic throttling, set this to None.
Check out the example directory for more information.
Using DomainKeys is entirely optional, however it is recommended by Amazon for authenticating your email address and improving delivery success rate. See http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/DKIM.html. Besides authentication, you might also want to consider using DKIM in order to remove the via email-bounces.amazonses.com message shown to gmail users - see http://support.google.com/mail/bin/answer.py?hl=en&answer=1311182.
To enable DKIM signing you should install the pydkim package and specify values for the DKIM_PRIVATE_KEY and DKIM_DOMAIN settings. You can generate a private key with a command such as openssl genrsa 512 and get the public key portion with openssl rsa -pubout <private.key. The public key should be published to ses._domainkey.example.com if your domain is example.com. You can use a different name instead of ses by changing the DKIM_SELECTOR setting.
The SES relay will modify email headers such as Date and Message-Id so by default only the From, To, Cc, Subject headers are signed, not the full set of headers. This is sufficient for most DKIM validators but can be overridden with the DKIM_HEADERS setting.
DKIM_DOMAIN = 'example.com' DKIM_PRIVATE_KEY = ''' -----BEGIN RSA PRIVATE KEY----- xxxxxxxxxxx -----END RSA PRIVATE KEY----- '''
Example DNS record published to Route53 with boto:
route53 add_record ZONEID ses._domainkey.example.com. TXT '"v=DKIM1; p=xxx"' 86400
Django SES comes with two ways of viewing sending statistics.
The first one is a simple read-only report on your 24 hour sending quota, verified email addresses and bi-weekly sending statistics.
To generate and view SES sending statistics reports, include, update INSTALLED_APPS:
INSTALLED_APPS = ( # ... 'django.contrib.admin', 'django_ses', # ... )
... and urls.py:
urlpatterns += (url(r'^admin/django-ses/', include('django_ses.urls')),)
Optional enhancements to stats:
You can install pytz to localize the Amazon timestamp (assumed UTC) to your locale. This will also make the date more readable, using Django's default formatting.
You can use adminplus for this (https://github.com/jsocol/django-adminplus):
from django_ses.views import dashboard admin.site.register_view('django-ses', dashboard, 'Django SES Stats')
If you need to keep send statistics around for longer than two weeks, django-ses also comes with a model that lets you store these. To use this feature you'll need to first run syncdb:
python manage.py syncdb
To collect the statistics, run the get_ses_statistics management command (refer to next section for details). After running this command the statistics will be viewable via /admin/django_ses/.
To use these you must include django_ses in your INSTALLED_APPS.
Manage verified email addresses through the management command.
python manage.py ses_email_address -l
To collect and store SES sending statistics in the database, run:
python manage.py get_ses_statistics
Sending statistics are aggregated daily (UTC time). Stats for the latest day (when you run the command) may be inaccurate if run before end of day (UTC). If you want to keep your statistics up to date, setup cron to run this command a short time after midnight (UTC) daily.
If you'd like Django's Builtin Email Error Reporting to function properly (actually send working emails), you'll have to explicitly set the SERVER_EMAIL setting to one of your SES-verified addresses. Otherwise, your error emails will all fail and you'll be blissfully unaware of a problem.
Note: You will need to sign up for SES and verify any emails you're going to use in the from_email argument to django.core.mail.send_email(). Boto has a verify_email_address() method: https://github.com/boto/boto/blob/master/boto/ses/connection.py
django-ses requires boto version 2.1.0 or later.
If you'd like to fix a bug, add a feature, etc
Be explicit so that project collaborators can understand and reproduce the issue, or decide whether the feature falls within the project's goals. Code examples can be useful, too.
You may write a prototype or suggested fix.
Write your own test showing the issue has been resolved, or the feature works as intended.
To run the tests:
python manage.py test django_ses
|File||Type||Python Version||Uploaded On||Downloads|
|django-ses-0.7.0.tar.gz||Source||Nov. 20, 2014||41,264|
|0.7.0||Nov. 20, 2014|
|0.6.0||Feb. 27, 2014|
|0.4.1||March 17, 2012|
|0.4.0||Feb. 21, 2012|
|0.3.0||Feb. 5, 2012|
|0.2||April 16, 2011|
|0.1||March 7, 2011|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.4.0||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.4.1||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.7.0||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.6.0||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.3.0||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.1||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||0.2||Release Created|
|Aug. 26, 2015, 12:24 a.m.||django-ses||Package Created|