Code

#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

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?

Attachments (0)

Change History (7)

comment:1 Changed 15 months 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 14 months ago by CarstenF

  • Cc carsten.fuchs@… added

comment:3 Changed 14 months ago by Kamu

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

comment:4 Changed 13 months ago by axelingolfsson@…

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

comment:5 Changed 13 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 13 months ago by claudep

No, only Python < 2.6.6 is affected.

comment:7 Changed 11 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.