mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Rename EmailBackends for Django consistency
* **Future breaking change:** Rename all Anymail backends to just `EmailBackend`, matching Django's naming convention. (E.g., switch to "anymail.backends.mailgun.EmailBackend" rather than "anymail.backends.mailgun.MailgunBackend".) The old names still work, but will issue a DeprecationWarning and will be removed in some future release. (Apologies for this change; the old naming convention was a holdover from Djrill, and I wanted consistency with other Django EmailBackends before hitting 1.0.) Fixes #49.
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
|
||||
from ..exceptions import AnymailRequestsAPIError, AnymailError
|
||||
from ..exceptions import AnymailRequestsAPIError, AnymailError, AnymailDeprecationWarning
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting, rfc2822date
|
||||
|
||||
from .base_requests import AnymailRequestsBackend, RequestsPayload
|
||||
|
||||
|
||||
class MailgunBackend(AnymailRequestsBackend):
|
||||
class EmailBackend(AnymailRequestsBackend):
|
||||
"""
|
||||
Mailgun API Email Backend
|
||||
"""
|
||||
|
||||
esp_name = "Mailgun"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Init options from Django settings"""
|
||||
esp_name = self.esp_name
|
||||
@@ -22,7 +25,7 @@ class MailgunBackend(AnymailRequestsBackend):
|
||||
default="https://api.mailgun.net/v3")
|
||||
if not api_url.endswith("/"):
|
||||
api_url += "/"
|
||||
super(MailgunBackend, self).__init__(api_url, **kwargs)
|
||||
super(EmailBackend, self).__init__(api_url, **kwargs)
|
||||
|
||||
def build_message_payload(self, message, defaults):
|
||||
return MailgunPayload(message, defaults, self)
|
||||
@@ -52,6 +55,15 @@ class MailgunBackend(AnymailRequestsBackend):
|
||||
return {recipient.email: status for recipient in payload.all_recipients}
|
||||
|
||||
|
||||
# Pre-v0.8 naming (deprecated)
|
||||
class MailgunBackend(EmailBackend):
|
||||
def __init__(self, **kwargs):
|
||||
warnings.warn(AnymailDeprecationWarning(
|
||||
"Please update your EMAIL_BACKEND setting to "
|
||||
"'anymail.backends.mailgun.EmailBackend'"))
|
||||
super(MailgunBackend, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class MailgunPayload(RequestsPayload):
|
||||
|
||||
def __init__(self, message, defaults, backend, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user