This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author simon04
Recipients simon04
Date 2015-10-15.13:02:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1444914126.08.0.971116617077.issue25411@psf.upfronthosting.co.za>
In-reply-to
Content
This relates to the unresolved issue9208 (Python 2).

SMTPHandler fails when receiving unicode strings.

Example (from msg109621):
import logging,logging.handlers
smtpHandler = logging.handlers.SMTPHandler(
    mailhost=("smtp.free.fr",25),
    fromaddr="from@free.fr", toaddrs="to@free.fr",
    subject=u"error message")
LOG = logging.getLogger()
LOG.addHandler(smtpHandler)
LOG.error(u"accentu\u00E9")

… fails:
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.5/logging/handlers.py", line 985, in emit
    smtp.sendmail(self.fromaddr, self.toaddrs, msg)
  File "/usr/lib/python3.5/smtplib.py", line 846, in sendmail
    msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 108: ordinal not in range(128)
Call stack:
  File "/tmp/x.py", line 8, in <module>
    LOG.error(u"accentu\u00E9")
Message: 'accentué'
Arguments: ()

As discussed in msg252928 and msg252931, EmailMessage/send_message should be used instead to resolve this issue.

Patch attached.
History
Date User Action Args
2015-10-15 13:02:06simon04setrecipients: + simon04
2015-10-15 13:02:06simon04setmessageid: <1444914126.08.0.971116617077.issue25411@psf.upfronthosting.co.za>
2015-10-15 13:02:06simon04linkissue25411 messages
2015-10-15 13:02:05simon04create