This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: When using an SMTP SSL connection,, get ValueError.
Type: behavior Stage: patch review
Components: email Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dadeos, amcgregor, barry, cheryl.sabella, christian.heimes, dstufft, gertburger, python-dev, r.david.murray, tyrone-zhao
Priority: normal Keywords: patch

Created on 2019-02-23 17:44 by tyrone-zhao, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
1.png tyrone-zhao, 2019-02-23 17:44 How does it happen
Pull Requests
URL Status Linked Edit
PR 11998 closed python-dev, 2019-02-23 17:57
PR 23490 closed python-dev, 2020-12-03 15:01
PR 23635 open python-dev, 2020-12-04 10:04
Messages (4)
msg336393 - (view) Author: 赵军昱 (tyrone-zhao) * Date: 2019-02-23 17:44
The following bug occurs when you connect after creating an instance of SMTP_SSL:
```
import smtplib


smtp_server = "smtp.163.com"
con2 = smtplib.SMTP_SSL()
con2.connect(smtp_server, 465)
```
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)
msg336404 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-02-23 21:01
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 issue19785 and @dstufft as he modified it to be `self._host`.
msg376344 - (view) Author: Peter Stokes (Dadeos) Date: 2020-09-04 09:52
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 issue41470 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]).

[1] https://github.com/python/cpython/pull/11998/commits/e445ccbc483dfde74638dbb694132dc00ced4973
[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
msg377833 - (view) Author: Alice Bevan-McGregor (amcgregor) Date: 2020-10-02 20:11
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.

https://github.com/marrow/mailer/issues/83 is our own tracking issue, with https://github.com/marrow/mailer/pull/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.)
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80275
2021-02-24 05:51:21gertburgersetnosy: + gertburger
2020-12-04 10:04:16python-devsetpull_requests: + pull_request22503
2020-12-03 15:01:40python-devsetnosy: + python-dev
pull_requests: + pull_request22499
2020-10-02 20:11:40amcgregorsetnosy: + amcgregor
messages: + msg377833
2020-09-04 09:52:53Dadeossetnosy: + Dadeos
messages: + msg376344
2019-02-23 21:01:31cheryl.sabellasetnosy: + christian.heimes, dstufft, cheryl.sabella
messages: + msg336404
2019-02-23 18:05:23SilentGhostsetstage: patch review
2019-02-23 18:05:05SilentGhostsetstage: patch review -> (no value)
type: resource usage -> behavior
versions: + Python 3.8
2019-02-23 17:57:38python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12027
2019-02-23 17:44:01tyrone-zhaocreate