mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Raise error for invalidly-formatted email addresses.
A message's `from_email` and each address in its `to`, `cc`, and `bcc` lists must contain exactly one email address. Previous code would silently ignore additional addresses, leading to unusual behavior. Now, raises new `AnymailInvalidAddress` exception. Example: `from_email='Widgets, Inc. <widgets@example.com>'` is invalid: it needs double-quotes around the "Widgets, Inc." display-name portion. In earlier versions, this probably would have sent the message from something like "From: Widgets <@localhost>". Now, it will raise an exception. **Potentially-breaking change:** If your code is using an unquoted display-name containing a comma in an email address, it will now raise an error. In earlier versions, this may have appeared to succeed, but was almost certainly not doing what you intended. Fixes #44.
This commit is contained in:
@@ -36,6 +36,26 @@ Exceptions
|
||||
your ESP's dashboard. See :ref:`troubleshooting`.)
|
||||
|
||||
|
||||
.. exception:: AnymailInvalidAddress
|
||||
|
||||
.. versionadded:: 0.7
|
||||
|
||||
The send call will raise a :exc:`!AnymailInvalidAddress` error if you
|
||||
attempt to send a message with invalidly-formatted email addresses in
|
||||
the :attr:`from_email` or recipient lists.
|
||||
|
||||
One source of this error can be using a display-name ("real name") containing
|
||||
commas or parentheses. Per :rfc:`5322`, you should use double quotes around
|
||||
the display-name portion of an email address:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# won't work:
|
||||
send_mail(from_email='Widgets, Inc. <widgets@example.com>', ...)
|
||||
# must use double quotes around display-name containing comma:
|
||||
send_mail(from_email='"Widgets, Inc." <widgets@example.com>', ...)
|
||||
|
||||
|
||||
.. exception:: AnymailSerializationError
|
||||
|
||||
The send call will raise a :exc:`!AnymailSerializationError`
|
||||
|
||||
Reference in New Issue
Block a user