mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Backend: Remove obsolete api_verify altogether.
Remove connection management (remnant of sender verification, and didn't match Django email backend signatures). Reformat inherited patch to 80-char line width. Consistent int return type from send_messages.
This commit is contained in:
@@ -33,7 +33,6 @@ class DjrillBackend(BaseEmailBackend):
|
|||||||
super(DjrillBackend, self).__init__(**kwargs)
|
super(DjrillBackend, self).__init__(**kwargs)
|
||||||
self.api_key = getattr(settings, "MANDRILL_API_KEY", None)
|
self.api_key = getattr(settings, "MANDRILL_API_KEY", None)
|
||||||
self.api_url = getattr(settings, "MANDRILL_API_URL", None)
|
self.api_url = getattr(settings, "MANDRILL_API_URL", None)
|
||||||
self.connection = None
|
|
||||||
|
|
||||||
if not self.api_key:
|
if not self.api_key:
|
||||||
raise ImproperlyConfigured("You have not set your mandrill api key "
|
raise ImproperlyConfigured("You have not set your mandrill api key "
|
||||||
@@ -43,35 +42,14 @@ class DjrillBackend(BaseEmailBackend):
|
|||||||
"url to your settings.py")
|
"url to your settings.py")
|
||||||
|
|
||||||
self.api_action = self.api_url + "/messages/send.json"
|
self.api_action = self.api_url + "/messages/send.json"
|
||||||
self.api_verify = self.api_url + "/users/ping.json"
|
|
||||||
|
|
||||||
def open(self, sender):
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
self.connection = None
|
|
||||||
|
|
||||||
valid_sender = requests.post(
|
|
||||||
self.api_verify, data={"key": self.api_key})
|
|
||||||
|
|
||||||
if valid_sender.status_code == 200:
|
|
||||||
self.connection = True
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
if not self.fail_silently:
|
|
||||||
raise
|
|
||||||
|
|
||||||
def send_messages(self, email_messages):
|
def send_messages(self, email_messages):
|
||||||
if not email_messages:
|
if not email_messages:
|
||||||
return
|
return 0
|
||||||
|
|
||||||
num_sent = 0
|
num_sent = 0
|
||||||
for message in email_messages:
|
for message in email_messages:
|
||||||
self.open(message.from_email)
|
|
||||||
if not self.connection:
|
|
||||||
return
|
|
||||||
|
|
||||||
sent = self._send(message)
|
sent = self._send(message)
|
||||||
|
|
||||||
if sent:
|
if sent:
|
||||||
num_sent += 1
|
num_sent += 1
|
||||||
|
|
||||||
@@ -103,7 +81,10 @@ class DjrillBackend(BaseEmailBackend):
|
|||||||
|
|
||||||
if djrill_it.status_code != 200:
|
if djrill_it.status_code != 200:
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise DjrillBackendHTTPError(status_code=djrill_it.status_code, log_message="Failed to send a message to %s, from %s" % (self.recipients, self.sender))
|
raise DjrillBackendHTTPError(
|
||||||
|
status_code=djrill_it.status_code,
|
||||||
|
log_message="Failed to send a message to %s, from %s" %
|
||||||
|
(self.recipients, self.sender))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user