py3 compat when sending emails with non-ascii content

This commit is contained in:
Kovid Goyal 2021-02-23 21:44:11 +05:30
parent 1d3f6d3dd9
commit 98da158ca6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -163,6 +163,8 @@ def get_smtp_class(use_ssl=False, debuglevel=0):
def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=None,
relay=None, username=None, password=None, encryption='TLS',
port=-1, debug_output=None, verify_server_cert=False, cafile=None):
if isinstance(msg, str):
msg = msg.encode('utf-8')
if relay is None:
for x in to:
return sendmail_direct(from_, x, msg, timeout, localhost, verbose)