Permalink
Browse files

Updating to make use of boto 2.2's new, more specific SES exception c…

…lasses. Outbound retries will no longer happen for invalid or blacklisted addresses.
  • Loading branch information...
Greg Taylor
Greg Taylor committed Feb 8, 2012
1 parent 942ec46 commit 20a1f37992c929a0df686bc6fd95473565a1f2bf
Showing with 35 additions and 8 deletions.
  1. +6 −0 CHANGES
  2. +1 −1 seacucumber/__init__.py
  3. +26 −1 seacucumber/tasks.py
  4. +2 −6 setup.py
View
@@ -1,5 +1,11 @@
Sea Cucumber Change Log
+1.4
+===
+
+* Take advantage of new SES exceptions in boto to prevent the re-trying of
+ bounced or invalid email addresses.
+
1.3
===
* Assume default of 0 for current/prev day stats when no mails have been sent.
View
@@ -4,4 +4,4 @@
rest of the contents of this module are largely optional.
"""
# In the form of Major, Minor.
-VERSION = (1, 3)
+VERSION = (1, 4)
View
@@ -2,11 +2,14 @@
Supporting celery tasks go in this module. The primarily interesting one is
SendEmailTask, which handles sending a single Django EmailMessage object.
"""
+import logging
from django.conf import settings
from celery.task import Task
-from boto.ses import SESConnection
+from boto.ses.exceptions import SESAddressBlacklistedError, SESDomainEndsWithDotError
from seacucumber.util import get_boto_ses_connection
+logger = logging.getLogger(__name__)
+
class SendEmailTask(Task):
"""
Sends an email through Boto's SES API module.
@@ -39,7 +42,29 @@ def run(self, from_email, recipients, message):
destinations=recipients,
raw_message=message,
)
+ except SESAddressBlacklistedError, exc:
+ # Blacklisted users are those which delivery failed for in the
+ # last 24 hours. They'll eventually be automatically removed from
+ # the blacklist, but for now, this address is marked as
+ # undeliverable to.
+ logger.warning(
+ 'Attempted to email a blacklisted user: %s' % recipients,
+ exc_info=exc,
+ extra={'trace': True}
+ )
+ return False
+ except SESDomainEndsWithDotError, exc:
+ # Domains ending in a dot are simply invalid.
+ logger.warning(
+ 'Invalid recipient, ending in dot: %s' % recipients,
+ exc_info=exc,
+ extra={'trace': True}
+ )
+ return False
except Exception, exc:
+ # Something else happened that we haven't explicitly forbade
+ # retry attempts for.
+ #noinspection PyUnresolvedReferences
self.retry(exc=exc)
# We shouldn't ever block long enough to see this, but here it is
View
@@ -3,11 +3,7 @@
DESCRIPTION = "A Django email backend for Amazon Simple Email Service, backed by celery."
-LONG_DESCRIPTION = None
-try:
- LONG_DESCRIPTION = open('README.rst').read()
-except:
- pass
+LONG_DESCRIPTION = open('README.rst').read()
version_str = '%d.%d' % (seacucumber.VERSION[0], seacucumber.VERSION[1])
@@ -37,5 +33,5 @@
long_description=LONG_DESCRIPTION,
platforms=['any'],
classifiers=CLASSIFIERS,
- install_requires=['boto'],
+ install_requires=['boto>=2.2.1'],
)

0 comments on commit 20a1f37

Please sign in to comment.