Skip to content

gh-106432: Added WSL support for adjusting the local hostname #106432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Lib/smtplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import hmac
import copy
import datetime
import platform
import sys
from email.base64mime import body_encode as encode_base64

Expand Down Expand Up @@ -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
Expand Down