Message371801
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. |
|
Date |
User |
Action |
Args |
2020-06-18 09:45:34 | jpatel | set | recipients:
+ jpatel, barry, r.david.murray |
2020-06-18 09:45:34 | jpatel | set | messageid: <1592473534.66.0.101889528587.issue41023@roundup.psfhosted.org> |
2020-06-18 09:45:34 | jpatel | link | issue41023 messages |
2020-06-18 09:45:33 | jpatel | create | |
|