EmailMultiAlternatives.send() raises error when `to` isn't a list
|Reported by:||djoume@…||Owned by:||adrian|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Following http://www.djangoproject.com/documentation/email/, I have tried the example :
from django.core.mail import EmailMultiAlternatives subject, from_email, to = 'hello', 'firstname.lastname@example.org', 'email@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 ['firstname.lastname@example.org'] instead of 'email@example.com'
Another solution is to changed __init__() to force self.to and self.bcc to being list.
Change History (2)
comment:1 Changed 9 years ago by anonymous
- Component changed from Core framework to django.core.mail
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset