From 67d04d22232fac223fe30fbf9655a13fc42ad216 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Sun, 30 Mar 2014 17:30:43 -0700 Subject: [PATCH] allow sending via Amazon SES --- helios/utils.py | 5 +++-- helios/views.py | 2 +- requirements.txt | 2 ++ settings.py | 6 ++++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/helios/utils.py b/helios/utils.py index 2db3dd7..d053dc1 100644 --- a/helios/utils.py +++ b/helios/utils.py @@ -6,7 +6,8 @@ Ben Adida - ben@adida.net """ import urllib, re, sys, datetime, urlparse, string -import threading + +import boto.ses # utils from helios_auth, too from helios_auth.utils import * @@ -154,8 +155,8 @@ from django.core import mail as django_mail def send_email(sender, recpt_lst, subject, body): # subject up until the first newline subject = subject.split("\n")[0] + django_mail.send_mail(subject, body, sender, recpt_lst, fail_silently=True) - ## diff --git a/helios/views.py b/helios/views.py index 388fa99..44002da 100644 --- a/helios/views.py +++ b/helios/views.py @@ -447,7 +447,7 @@ Your trustee dashboard is at Helios """ % (election.name, url) - send_mail('your trustee homepage for %s' % election.name, body, settings.SERVER_EMAIL, ["%s <%s>" % (trustee.name, trustee.email)], fail_silently=True) + helios_utils.send_email(settings.SERVER_EMAIL, ["%s <%s>" % (trustee.name, trustee.email)], 'your trustee homepage for %s' % election.name, body) logging.info("URL %s " % url) return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(list_trustees_view, args = [election.uuid])) diff --git a/requirements.txt b/requirements.txt index 02d47dc..fa99dcf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,5 @@ webtest==2.0.7 django-db-pool==0.0.10 django-secure==0.1.2 bleach==1.4 +boto==2.27.0 +django-ses==0.6.0 diff --git a/settings.py b/settings.py index 5c90c6a..9734e43 100644 --- a/settings.py +++ b/settings.py @@ -231,6 +231,12 @@ EMAIL_HOST_USER = get_from_env('EMAIL_HOST_USER', '') EMAIL_HOST_PASSWORD = get_from_env('EMAIL_HOST_PASSWORD', '') EMAIL_USE_TLS = (get_from_env('EMAIL_USE_TLS', '0') == '1') +# to use AWS Simple Email Service +# in which case environment should contain +# AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY +if get_from_env('EMAIL_USE_AWS', '0') == '1': + EMAIL_BACKEND = 'django_ses.SESBackend' + # set up logging import logging logging.basicConfig( -- GitLab