New submission from Jay Patel <jay.pa...@crestdatasys.com>:
According to the user requirements, I need to send an email, which is provided as a raw email, i.e., the contents of email are provided in form of headers. To accomplish this I am using the methods provided in the "send_rawemail_demo.py" file (attached below). The smtplib library works fine when providing only 'ascii' characters in the 'raw_email' variable. But, when I provide any Unicode characters either in the Subject or Body of the email, then the sendmail method of the smtplib library fails with the following message: UnicodeEncodeError 'ascii' codec can't encode characters in position 123-124: ordinal not in range(128) I tried providing the mail_options=["SMTPUTF-8"] in the sendmail method (On line no. 72 in the send_rawemail_demo.py file), but then it fails (even for the 'ascii' characters) with the exception as SMTPSenderRefused. I have faced the same issue on Python 3.6. The sendmail method of the SMTP class encodes the message using 'ascii' as: if isinstance(msg, str): msg = _fix_eols(msg).encode('ascii') The code works properly for Python 2 as the smtplib library for Python 2 does not have the above line and hence it allows Unicode characters in the Body and the Subject. ---------- components: email files: send_rawemail_demo.py messages: 371801 nosy: barry, jpatel, r.david.murray priority: normal severity: normal status: open title: smtplib does not handle Unicode characters type: enhancement versions: Python 3.8 Added file: https://bugs.python.org/file49249/send_rawemail_demo.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41023> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com