def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addresses to send the message to. :param str message: The body of the message. """ self._open_ses_conn() try: # We use the send_raw_email func here because the Django # EmailMessage object we got these values from constructs all of # the headers and such. self.connection.send_raw_email( source=from_email, destinations=recipients, raw_message=dkim_sign(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
def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addresses to send the message to. :param str message: The body of the message. """ client = self._get_boto_ses_client() try: # We use the send_raw_email func here because the Django # EmailMessage object we got these values from constructs all of # the headers and such. client.send_raw_email( Source=from_email, Destinations=recipients, RawMessage={"Data": dkim_sign(message)}, ) except client.exceptions.AccountSendingPausedException as exc: # Happens when the account gets disabled. We shouldn't be retrying this logger.warning("SES Account Paused", exc_info=exc, extra={"trace": True}) return False except client.exceptions.MessageRejected as exc: # Message got rejected by SES. logger.warning( "Message intended for %s got rejected by AWS" % recipients, exc_info=exc, extra={"trace": True}, ) return False except client.exceptions.BaseClientException as exc: logger.error( "General SES Exception occured while trying to send to %s" % recipients, exc_info=exc, extra={"trace": True}, ) return False except Exception as exc: # Something else happened that we haven't explicitly forbade # retry attempts for. logger.error( "Something went wrong; retrying: %s" % recipients, exc_info=exc, extra={"trace": True}, ) self.retry(exc=exc) else: logger.info("An email has been successfully sent: %s" % recipients) # We shouldn't ever block long enough to see this, but here it is # just in case (for debugging?). return True
def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addresses to send the message to. :param str message: The body of the message. """ self._open_ses_conn() try: # We use the send_raw_email func here because the Django # EmailMessage object we got these values from constructs all of # the headers and such. self.connection.send_raw_email( Source=from_email, Destinations=recipients, RawMessage={ 'Data': dkim_sign(message), }, ) except Exception as exc: # Something else happened that we haven't explicitly forbade # retry attempts for. # noinspection PyUnresolvedReferences logger.error('Something went wrong; retrying: %s' % recipients, exc_info=exc, extra={'trace': True}) self.retry(exc=exc) else: logger.info('An email has been successfully sent: %s' % recipients) # We shouldn't ever block long enough to see this, but here it is # just in case (for debugging?). return True
def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addresses to send the message to. :param str message: The body of the message. """ self._open_ses_conn() try: # We use the send_raw_email func here because the Django # EmailMessage object we got these values from constructs all of # the headers and such. self.connection.send_raw_email( source=from_email, destinations=recipients, raw_message=dkim_sign(message), ) except SESAddressBlacklistedError as 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 as 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 SESLocalAddressCharacterError as exc: # Invalid character, usually in the sender "name". logger.warning( 'Local address contains control or whitespace: %s' % recipients, exc_info=exc, extra={'trace': True} ) return False except SESIllegalAddressError as exc: # A clearly mal-formed address. logger.warning( 'Illegal address: %s' % recipients, exc_info=exc, extra={'trace': True} ) return False except Exception as exc: # Something else happened that we haven't explicitly forbade # retry attempts for. #noinspection PyUnresolvedReferences logger.error( 'Something went wrong; retrying: %s' % recipients, exc_info=exc, extra={'trace': True} ) self.retry(exc=exc) else: logger.info('An email has been successfully sent: %s' % recipients) # We shouldn't ever block long enough to see this, but here it is # just in case (for debugging?). return True
def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addresses to send the message to. :param str message: The body of the message. """ self._open_ses_conn() try: # We use the send_raw_email func here because the Django # EmailMessage object we got these values from constructs all of # the headers and such. self.connection.send_raw_email( source=from_email, destinations=recipients, raw_message=dkim_sign(message), ) except SESAddressBlacklistedError as 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 as 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 SESLocalAddressCharacterError as exc: # Invalid character, usually in the sender "name". logger.warning( 'Local address contains control or whitespace: %s' % recipients, exc_info=exc, extra={'trace': True} ) return False except SESIllegalAddressError as exc: # A clearly mal-formed address. logger.warning( 'Illegal address: %s' % recipients, exc_info=exc, extra={'trace': True} ) return False except Exception as exc: # Something else happened that we haven't explicitly forbade # retry attempts for. logger.error( 'Something went wrong; retrying: %s' % recipients, exc_info=exc, extra={'trace': True} ) self.retry(exc=exc) else: logger.info('An email has been successfully sent: %s' % recipients) # We shouldn't ever block long enough to see this, but here it is # just in case (for debugging?). return True