If from_email
is not provided, EmailMessage
or EmailMultiAlternatives
will use DEFAULT_FROM_EMAIL
. If DEFAULT_FROM_EMAIL is not a tuple sanitize_address
will pass DEFAULT_FROM_EMAIL to the function parseaddr
from the email
module in the standard library. parseaddr
will then try to parse RFC 2822 addresses.
Space and "(),:;<>@[\] characters are allowed with restrictions (https://stackoverflow.com/a/2049510/4819353). If you pass a suqare bracket [
to parseaddr
it will return someting like this: [('', ''), ('', 'test'), ('', ''), ('Bob', 'noreply@example.com')]
. Since sanitize_address
will use only the first element from the returned list, you will get an error.
I suggest that the documentation mentions some of this.
DEFAULT_FROM_EMAIL¶
...
The value should be a tuple containing two strings, `(name, address)`, or a string in the form of `name <email@example.com>`.