Opened 8 years ago

Closed 8 years ago

#4906 closed (invalid)

EmailMultiAlternatives.send() raises error when `to` isn't a list

Reported by: djoume@… Owned by: adrian
Component: Core (Mail) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



Following, I have tried the example :

from django.core.mail import EmailMultiAlternatives

subject, from_email, to = 'hello', '', ''
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")

This raise a "cannot concatenate 'str' and 'list' objects" error.
The exception is raised by return + self.bcc (line 251 in
because bcc is set to [] by default (line 209 of and in this example to is a string.

To fix this I had to use [''] instead of ''

Another solution is to changed __init__() to force and self.bcc to being list.

Change History (2)

comment:1 Changed 8 years ago by anonymous

  • Component changed from Core framework to django.core.mail
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by SmileyChris

  • Resolution set to invalid
  • Status changed from new to closed
  • Summary changed from EmailMultiAlternatives.send() raise coercing to Unicode when bcc is None to 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). Coercing to to a list wouldn't achieve much, you'd just end up with ['t', 'o', '@', ...]

Note: See TracTickets for help on using tickets.
Back to Top