Opened 13 years ago
Closed 12 years ago
#20230 closed Bug (wontfix)
Can't send unicode email (HTML emails using EmailMultiAlternatives)
| Reported by: | James Addison | Owned by: | |
|---|---|---|---|
| Component: | Core (Mail) | Version: | 1.5 |
| Severity: | Normal | Keywords: | |
| Cc: | carsten.fuchs@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | yes |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
This is directly related to https://code.djangoproject.com/ticket/19107, but the steps differ:
from django.core.mail.message import EmailMultiAlternatives # the character is some sort of fancy dash/hyphen subject = body_text = body_html = u'\u2013' e = EmailMultiAlternatives(subject, body_text, 'from@example.com', ['to@example.com']) e.attach_alternative(body_html, 'text/html') e.send()
This results:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/chatterblockteam/live/lib/python2.6/site-packages/django/core/mail/message.py", line 255, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/chatterblockteam/live/lib/python2.6/site-packages/django/core/mail/backends/smtp.py", line 95, in send_messages
sent = self._send(message)
File "/home/chatterblockteam/live/lib/python2.6/site-packages/django/core/mail/backends/smtp.py", line 113, in _send
force_bytes(message.as_string(), charset))
File "/home/chatterblockteam/live/lib/python2.6/site-packages/django/core/mail/message.py", line 169, in as_string
g.flatten(self, unixfrom=unixfrom)
File "/usr/lib/python2.6/email/generator.py", line 84, in flatten
self._write(msg)
File "/usr/lib/python2.6/email/generator.py", line 109, in _write
self._dispatch(msg)
File "/usr/lib/python2.6/email/generator.py", line 135, in _dispatch
meth(msg)
File "/usr/lib/python2.6/email/generator.py", line 201, in _handle_multipart
g.flatten(part, unixfrom=False)
File "/usr/lib/python2.6/email/generator.py", line 84, in flatten
self._write(msg)
File "/usr/lib/python2.6/email/generator.py", line 109, in _write
self._dispatch(msg)
File "/usr/lib/python2.6/email/generator.py", line 135, in _dispatch
meth(msg)
File "/usr/lib/python2.6/email/generator.py", line 178, in _handle_text
self._fp.write(payload)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 0: ordinal not in range(128)
As with the referenced ticket above, the root cause must lie with http://bugs.python.org/issue1368247; python 2.7.x works fine while 2.6.5 (on our production server running Ubuntu 10.04) it does the above. I assume that a similar fix is needed for attachments and not just text. I wonder if subject and to/from lines are similarly problematic?
Change History (7)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
| Cc: | added |
|---|
comment:3 by , 12 years ago
| Needs documentation: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:4 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 12 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
I can't reproduce this in python2.7, django 1.4.
comment:7 by , 12 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
Marking as won't fix since no one wrote a complete patch as requested by @claudep and 1.7 is dropping support for Python 2.6.
Personally, I'd rather document the bug than working around outdated versions of Python. If anyone proposes a complete patch with tests, it has a chance to go in, otherwise it might end up as "won't fix"...