Opened 2 years ago

Closed 20 months ago

#20230 closed Bug (wontfix)

Can't send unicode email (HTML emails using EmailMultiAlternatives)

Reported by: jaddison 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


This is directly related to, 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, '', [''])
e.attach_alternative(body_html, 'text/html')

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/", 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/", line 95, in send_messages
    sent = self._send(message)
  File "/home/chatterblockteam/live/lib/python2.6/site-packages/django/core/mail/backends/", line 113, in _send
    force_bytes(message.as_string(), charset))
  File "/home/chatterblockteam/live/lib/python2.6/site-packages/django/core/mail/", line 169, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib/python2.6/email/", line 84, in flatten
  File "/usr/lib/python2.6/email/", line 109, in _write
  File "/usr/lib/python2.6/email/", line 135, in _dispatch
  File "/usr/lib/python2.6/email/", line 201, in _handle_multipart
    g.flatten(part, unixfrom=False)
  File "/usr/lib/python2.6/email/", line 84, in flatten
  File "/usr/lib/python2.6/email/", line 109, in _write
  File "/usr/lib/python2.6/email/", line 135, in _dispatch
  File "/usr/lib/python2.6/email/", line 178, in _handle_text
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; 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 Changed 2 years ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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"...

comment:2 Changed 23 months ago by CarstenF

  • Cc carsten.fuchs@… added

comment:3 Changed 22 months ago by Kamu

  • Needs documentation set
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 21 months ago by axelingolfsson@…

  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

comment:5 Changed 21 months ago by Axel Davíð Ingólfsson <axelingolfsson@…>

  • Owner anonymous deleted
  • Status changed from assigned to new

I can't reproduce this in python2.7, django 1.4.

comment:6 Changed 21 months ago by claudep

No, only Python < 2.6.6 is affected.

comment:7 Changed 20 months ago by charettes

  • Resolution set to wontfix
  • Status changed from new to 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.

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