You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When using an SMTP SSL connection,, get ValueError. #80275
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2019-02-23.17:44:01.948>labels= ['3.8', 'type-bug', '3.7', 'expert-email']
title='When using an SMTP SSL connection,, get ValueError.'updated_at=<Date2021-02-24.05:51:21.028>user='https://github.com/tyrone-zhao'
ValueError:
server_hostname cannot be an empty string or start with a leading dot.
File "E:\code\noUse.py", line 8, in <module>
con2.connect(smtp_server, 465)
tyrone-zhao, thank you for the report and the detail on the commit.
Adding @christian.heimes to the nosylist as he added change this under bpo-19785 and @dstufft as he modified it to be self._host.
Dadeos commented on Sep 4, 2020
Dadeosmannequin
Mannequin
More actions
I wanted to enquire as to if/when the proposed PR11998 is likely to be merged?
I also wanted to note the similarity between this issue and bpo-41470 and to suggest that whilst the change proposed in commit e445ccbc of PR11998 [1] would be welcome, there may be a case for exposing the value ultimately passed as the server_hostname parameter to the SSLContext.wrap_socket(…) call [2] as a parameter to SMTP.connect(…) [3]. Doing so would aid potential use cases whereby the host parameter provided is an address, yet the TLS server hostname validation should be based upon another value (i.e. the hostname); potentially useful in scenarios where the host's address has been previously derived, by the caller, by other means (e.g. a call to socket.getaddrinfo(…) [4]).
Howdy! One of my projects, Marrow Mailer (formerly TurboMail) has received a bit of a flood of reports and erroneous pull requests attempting to correct this bug in the invocation of smtplib by Mailer.
marrow/mailer#83 is our own tracking issue, with marrow/mailer#91 as the most "successful" pull request with more detailed (contextualized) traceback, comparison, and links to official documentation. (Also, yay, worked around the problem here by recovering my "native" issue tracker account rather than trying to sign in with GitHub.)
This appears to be a clear regression. The particular reason why I'm unwilling to accept these patches to Mailer is that passing a hostname at SMTP_SSL instantiation time will cause the connection to be initiated from within __init__ itself, prior to any ability to set the diagnostic logging level, which is boo, hiss. Initializers actually doing things is un-good, beyond diagnostic logging not being an optional keyword argument. (Instantiation != procedural invocation.)
#115259 has been merged to fix this issue. server_hostname as a separate parameter would be a feature request and should go in a new issue. if you see any problems with the committed fix, please comment there.
Activity
tyrone-zhao commentedon Feb 23, 2019
The following bug occurs when you connect after creating an instance of SMTP_SSL:
ValueError:
server_hostname cannot be an empty string or start with a leading dot.
File "E:\code\noUse.py", line 8, in <module>
con2.connect(smtp_server, 465)
csabella commentedon Feb 23, 2019
tyrone-zhao, thank you for the report and the detail on the commit.
Adding @christian.heimes to the nosylist as he added change this under bpo-19785 and @dstufft as he modified it to be
self._host.Dadeos commentedon Sep 4, 2020
I wanted to enquire as to if/when the proposed PR11998 is likely to be merged?
I also wanted to note the similarity between this issue and bpo-41470 and to suggest that whilst the change proposed in commit e445ccbc of PR11998 [1] would be welcome, there may be a case for exposing the value ultimately passed as the
server_hostnameparameter to theSSLContext.wrap_socket(…)call [2] as a parameter toSMTP.connect(…)[3]. Doing so would aid potential use cases whereby thehostparameter provided is an address, yet the TLS server hostname validation should be based upon another value (i.e. the hostname); potentially useful in scenarios where thehost's address has been previously derived, by the caller, by other means (e.g. a call tosocket.getaddrinfo(…)[4]).[1] e445ccb
[2] https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket
[3] https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.connect
[4] https://docs.python.org/3/library/socket.html#socket.getaddrinfo
amcgregor commentedon Oct 2, 2020
Howdy! One of my projects, Marrow Mailer (formerly TurboMail) has received a bit of a flood of reports and erroneous pull requests attempting to correct this bug in the invocation of smtplib by Mailer.
marrow/mailer#83 is our own tracking issue, with marrow/mailer#91 as the most "successful" pull request with more detailed (contextualized) traceback, comparison, and links to official documentation. (Also, yay, worked around the problem here by recovering my "native" issue tracker account rather than trying to sign in with GitHub.)
This appears to be a clear regression. The particular reason why I'm unwilling to accept these patches to Mailer is that passing a hostname at SMTP_SSL instantiation time will cause the connection to be initiated from within __init__ itself, prior to any ability to set the diagnostic logging level, which is boo, hiss. Initializers actually doing things is un-good, beyond diagnostic logging not being an optional keyword argument. (Instantiation != procedural invocation.)
Leetcore commentedon Aug 29, 2023
I have a Ubuntu 22.04.3 LTS server with Python 3.10.12 and this exact problem:
SMTP_SSL(hostname)just freezes!I found a workaround:
MonsieurCellophane commentedon Aug 8, 2024
Still there in 3.11.9 (after 5 years!)
Workaround mentioned in: https://stackoverflow.com/questions/51768041/python3-smtp-valueerror-server-hostname-cannot-be-an-empty-string-or-start-with#53385409
fix: Pass in server address when creating SMTP connection
bitdancer commentedon Apr 8, 2026
#115259 has been merged to fix this issue. server_hostname as a separate parameter would be a feature request and should go in a new issue. if you see any problems with the committed fix, please comment there.