From 0d4559f0fe8bf7df5187e5fc73596496e6f57a90 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 31 Oct 2020 19:00:32 +0530 Subject: [PATCH] Windows: Fix sending email on computers with non-ascii computer names --- src/calibre/utils/smtp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index b716099f5b..68dfdde3c9 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -34,7 +34,13 @@ def safe_localhost(): # RFC 2821 says we should use the fqdn in the EHLO/HELO verb, and # if that can't be calculated, that we should use a domain literal # instead (essentially an encoded IP address like [A.B.C.D]). - fqdn = decode_fqdn(socket.getfqdn()) + try: + fqdn = decode_fqdn(socket.getfqdn()) + except UnicodeDecodeError: + if not iswindows: + raise + from calibre_extensions.winutil import get_computer_name + fqdn = get_computer_name() if '.' in fqdn and fqdn != '.': # Some mail servers have problems with non-ascii local hostnames, see # https://bugs.launchpad.net/bugs/1256549