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:
@@ -5,16 +5,18 @@ from django.core.mail import make_msgid
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
|
||||
from .base_requests import AnymailRequestsBackend, RequestsPayload
|
||||
from ..exceptions import AnymailConfigurationError, AnymailRequestsAPIError, AnymailWarning
|
||||
from ..exceptions import AnymailConfigurationError, AnymailRequestsAPIError, AnymailWarning, AnymailDeprecationWarning
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting, timestamp, update_deep
|
||||
|
||||
|
||||
class SendGridBackend(AnymailRequestsBackend):
|
||||
class EmailBackend(AnymailRequestsBackend):
|
||||
"""
|
||||
SendGrid v3 API Email Backend
|
||||
"""
|
||||
|
||||
esp_name = "SendGrid"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Init options from Django settings"""
|
||||
esp_name = self.esp_name
|
||||
@@ -46,7 +48,7 @@ class SendGridBackend(AnymailRequestsBackend):
|
||||
default="https://api.sendgrid.com/v3/")
|
||||
if not api_url.endswith("/"):
|
||||
api_url += "/"
|
||||
super(SendGridBackend, self).__init__(api_url, **kwargs)
|
||||
super(EmailBackend, self).__init__(api_url, **kwargs)
|
||||
|
||||
def build_message_payload(self, message, defaults):
|
||||
return SendGridPayload(message, defaults, self)
|
||||
@@ -64,6 +66,15 @@ class SendGridBackend(AnymailRequestsBackend):
|
||||
return {recipient.email: status for recipient in payload.all_recipients}
|
||||
|
||||
|
||||
# Pre-v0.8 naming (deprecated)
|
||||
class SendGridBackend(EmailBackend):
|
||||
def __init__(self, **kwargs):
|
||||
warnings.warn(AnymailDeprecationWarning(
|
||||
"Please update your EMAIL_BACKEND setting to "
|
||||
"'anymail.backends.sendgrid.EmailBackend'"))
|
||||
super(SendGridBackend, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class SendGridPayload(RequestsPayload):
|
||||
|
||||
def __init__(self, message, defaults, backend, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user