mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Mailgun, SparkPost: support multiple from_email addresses
[RFC-5322 allows](https://tools.ietf.org/html/rfc5322#section-3.6.2) multiple addresses in the From header. Django's SMTP backend supports this, as a single comma-separated string (*not* a list of strings like the recipient params): from_email='one@example.com, two@example.com' to=['one@example.com', 'two@example.com'] Both Mailgun and SparkPost support multiple From addresses (and Postmark accepts them, though truncates to the first one on their end). For compatibility with Django -- and because Anymail attempts to support all ESP features -- Anymail now allows multiple From addresses, too, for ESPs that support it. Note: as a practical matter, deliverability with multiple From addresses is pretty bad. (Google outright rejects them.) This change also reworks Anymail's internal ParsedEmail object, and approach to parsing addresses, for better consistency with Django's SMTP backend and improved error messaging. In particular, Django (and now Anymail) allows multiple email addresses in a single recipient string: to=['one@example.com', 'two@example.com, three@example.com'] len(to) == 2 # but there will be three recipients Fixes #60
This commit is contained in:
@@ -7,7 +7,7 @@ from requests.structures import CaseInsensitiveDict
|
||||
from .base_requests import AnymailRequestsBackend, RequestsPayload
|
||||
from ..exceptions import AnymailConfigurationError, AnymailRequestsAPIError, AnymailWarning, AnymailDeprecationWarning
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting, timestamp, update_deep
|
||||
from ..utils import get_anymail_setting, timestamp, update_deep, parse_address_list
|
||||
|
||||
|
||||
class EmailBackend(AnymailRequestsBackend):
|
||||
@@ -115,7 +115,7 @@ class SendGridPayload(RequestsPayload):
|
||||
if "Reply-To" in headers:
|
||||
# Reply-To must be in its own param
|
||||
reply_to = headers.pop('Reply-To')
|
||||
self.set_reply_to([self.parsed_email(reply_to)])
|
||||
self.set_reply_to(parse_address_list([reply_to]))
|
||||
if len(headers) > 0:
|
||||
self.data["headers"] = dict(headers) # flatten to normal dict for json serialization
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user