Skip to content

Commit

Permalink
mailgun response hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aldarund committed Apr 27, 2016
1 parent 016d3ab commit d580e5e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions django_mailgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def _send(self, email_message):

to_recipients = [sanitize_address(addr, email_message.encoding)
for addr in email_message.to]

response = None
error = None
try:
post_data = []
post_data.append(('to', (",".join(to_recipients)),))
Expand Down Expand Up @@ -157,14 +158,15 @@ def _send(self, email_message):
response = requests.post(self._api_url + "messages",
auth=("api", self._access_key),
data=content, headers=headers)
except:
except Exception, e:
error = e
if not self.fail_silently:
raise
return False

mailgun_response_hook = getattr(settings, 'MAILGUN_RESPONSE_HOOK', None)
if mailgun_response_hook:
mailgun_response_hook(response, original_email_message)
finally:
mailgun_response_hook = getattr(settings, 'MAILGUN_RESPONSE_HOOK', None)
if mailgun_response_hook:
mailgun_response_hook(original_email_message, response, error)

if response.status_code != 200:
if not self.fail_silently:
Expand Down

0 comments on commit d580e5e

Please sign in to comment.