From 62835d4fd1377feb5cb9680468befb642c53badd Mon Sep 17 00:00:00 2001 From: Ineffable22 Date: Sun, 2 Jul 2023 20:30:09 -0500 Subject: [PATCH] Added WSL support for adjusting the local hostname --- Lib/smtplib.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py index 18c91746fd7bf2..020ab3e3ee3e7f 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -51,6 +51,7 @@ import hmac import copy import datetime +import platform import sys from email.base64mime import body_encode as encode_base64 @@ -263,7 +264,17 @@ def __init__(self, host='', port=0, local_hostname=None, # 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 = socket.getfqdn() - if '.' in fqdn: + + # Get information about the platform the program is running on + platform_string = platform.platform().lower() + + # Check if the environment is Windows Subsystem for Linux (WSL) + is_wsl = "microsoft" in platform_string and "linux" in platform_string + + # If it's WSL, adjust the hostname by removing the last character (the dot) + if is_wsl: + self.local_hostname = fqdn[:-1] + elif '.' in fqdn: self.local_hostname = fqdn else: # We can't find an fqdn hostname, so use a domain literal