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.

classification
Title: UnicodeEncodeError raise from smtplib.verify() method
Type: behavior Stage:
Components: Unicode Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Windson Yang, barry, ezio.melotti
Priority: normal Keywords:

Created on 2019-02-23 07:59 by Windson Yang, last changed 2022-04-11 14:59 by admin.

Messages (4)
msg336374 - (view) Author: Windson Yang (Windson Yang) * Date: 2019-02-23 07:59
AFAIK, the email address should support non-ASCII character (from https://stackoverflow.com/questions/760150/can-an-email-address-contain-international-non-english-characters and SMTPUTF8 
 option from https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.sendmail)

>>> import smtplib
>>> s = smtplib.SMTP(host='smtp-mail.outlook.com', port=587)
>>> s.verify('你好@outlook.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/windson/learn/cpython/Lib/smtplib.py", line 577, in verify
    self.putcmd("vrfy", _addr_only(address))
  File "/Users/windson/learn/cpython/Lib/smtplib.py", line 367, in putcmd
    self.send(str)
  File "/Users/windson/learn/cpython/Lib/smtplib.py", line 352, in send
    s = s.encode(self.command_encoding)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-6: ordinal not in range(128)

I found this issue when I updating https://github.com/python/cpython/pull/8938/files
msg336375 - (view) Author: Windson Yang (Windson Yang) * Date: 2019-02-23 08:04
Btw, from the docs https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.sendmail

> msg may be a string containing characters in the ASCII range, or a byte string. A string is encoded to bytes using the ascii codec, and lone \r and \n characters are converted to \r\n characters. A byte string is not modified.
 
So we can't send non-ASCII msg using send_mail(), is this expected behavior?
msg336509 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-02-25 10:14
Barry: would you mind to have a look at this issue? It seems like smtplib encodes Unicode commands to ASCII, whereas verify() argument (SMTP "VRFY" command) is an hostname and hostname can be non-ASCII ("punycode" encoding, RFC 3492).
msg365140 - (view) Author: Windson Yang (Windson Yang) * Date: 2020-03-27 09:07
Any update?
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80274
2020-03-27 11:16:23vstinnersetnosy: - vstinner
2020-03-27 09:07:12Windson Yangsetmessages: + msg365140
2019-02-25 10:14:54vstinnersetnosy: + barry
messages: + msg336509
2019-02-23 08:04:47Windson Yangsetmessages: + msg336375
2019-02-23 07:59:18Windson Yangcreate