Opened 17 years ago
Closed 17 years ago
#4906 closed (invalid)
EmailMultiAlternatives.send() raises error when `to` isn't a list
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Core (Mail) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
Following http://www.djangoproject.com/documentation/email/, I have tried the example :
from django.core.mail import EmailMultiAlternatives subject, from_email, to = 'hello', 'from@example.com', 'to@example.com' text_content = 'This is an important message.' html_content = '<p>This is an <strong>important</strong> message.' msg = EmailMultiAlternatives(subject, text_content, from_email, to) msg.attach_alternative(html_content, "text/html") msg.send()
This raise a "cannot concatenate 'str' and 'list' objects" error.
The exception is raised by return self.to + self.bcc
(line 251 in mail.py)
because bcc is set to [] by default (line 209 of mail.py) and in this example to is a string.
To fix this I had to use ['to@example.com']
instead of 'to@example.com'
Another solution is to changed __init__()
to force self.to
and self.bcc
to being list.
Change History (2)
comment:1 by , 17 years ago
Component: | Core framework → django.core.mail |
---|
comment:2 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Summary: | EmailMultiAlternatives.send() raise coercing to Unicode when bcc is None → EmailMultiAlternatives.send() raises error when `to` isn't a list |
Plain case of user error -
to
should always be a list (as the documentation clearly shows). Coercingto
to a list wouldn't achieve much, you'd just end up with['t', 'o', '@', ...]