Skip to content

gh-70039: smtplib: store the server name in ._host in .connect()#115259

Merged
bitdancer merged 8 commits intopython:mainfrom
nmartensen:70039_smtplib_host_port
Apr 8, 2026
Merged

gh-70039: smtplib: store the server name in ._host in .connect()#115259
bitdancer merged 8 commits intopython:mainfrom
nmartensen:70039_smtplib_host_port

Conversation

@nmartensen
Copy link
Copy Markdown
Contributor

@nmartensen nmartensen commented Feb 10, 2024

@nmartensen nmartensen requested a review from a team as a code owner February 10, 2024 21:09
@ghost
Copy link
Copy Markdown

ghost commented Feb 10, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Feb 10, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

nmartensen and others added 3 commits February 19, 2024 21:51
@nmartensen nmartensen force-pushed the 70039_smtplib_host_port branch from 5d822a0 to 5ea81fc Compare February 19, 2024 21:16
@nmartensen
Copy link
Copy Markdown
Contributor Author

The PR adds 6 tests in addition to the functional change. Most of them fail without the change:

  • In Lib/test/test_smtplib.py:DebuggingServerTests
    • test_host_port_host [fails] *
    • test_explicit_connect [fails]
    • text_explicit_connect_host_port [fails]
  • In Lib/test/test_smtpnet.py:SmtpTest
    • test_connect_host_port_starttls
    • test_explicit_connect_starttls [fails]
    • test_explicit_connect_host_port_starttls [fails]

The one that does not fail describes a situation that could sometimes also fail in practice before the change, see e.g. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=926900. The test marked with '*' above is meant to ensure this failure case won't be accidentally reintroduced in potential future changes.

@AliceGrey
Copy link
Copy Markdown

Any chance of getting this reviewed and merged? This bug has been open since 2019 and is still causing issues. This PR is excellent. It fixes the issue and adds several tests.

@jahs
Copy link
Copy Markdown

jahs commented Dec 17, 2025

Hi all, I'd like to echo the above as this is still an issue (going back to 2015). Caused an issue this week (December 2025) due to AWS SES eu-west-2 applying strict parsing in TLS of the self._host string (which they rolled back, in part due to this client bug). Specifically, the SMTP("host:port") constructor was used and it failed to connect, as the connect() parsing currently does not update self._host, which is then used in starttls().

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Dec 21, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

There are already other tests for the functionality, therefore there is
no need to test implementation details.
@nmartensen
Copy link
Copy Markdown
Contributor Author

nmartensen commented Dec 23, 2025

I have made the requested changes; please review again.

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Dec 23, 2025

Thanks for making the requested changes!

@bitdancer: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from bitdancer December 23, 2025 19:13
@nmartensen
Copy link
Copy Markdown
Contributor Author

There seem to be failing tests with this PR now. I have looked into them but fail to see what is needed to fix them. Please let me know if you know more.

@bitdancer
Copy link
Copy Markdown
Member

I think all you need to do is update to the tip of main. Let's try that, at least.

@bitdancer bitdancer merged commit 442f83a into python:main Apr 8, 2026
46 checks passed
@bitdancer bitdancer added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Apr 8, 2026
@miss-islington-app
Copy link
Copy Markdown

Thanks @nmartensen for the PR, and @bitdancer for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link
Copy Markdown

Thanks @nmartensen for the PR, and @bitdancer for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 8, 2026
pythonGH-115259)

Original patch by gigaplastik, extended with a few more tests.

Addresses pythongh-70039 and bpo-25852: failure of starttls if connect is called explicitly.
(cherry picked from commit 442f83a)

Co-authored-by: nmartensen <nis.martensen@web.de>
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 8, 2026

GH-148272 is a backport of this pull request to the 3.13 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 8, 2026
pythonGH-115259)

Original patch by gigaplastik, extended with a few more tests.

Addresses pythongh-70039 and bpo-25852: failure of starttls if connect is called explicitly.
(cherry picked from commit 442f83a)

Co-authored-by: nmartensen <nis.martensen@web.de>
@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Apr 8, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 8, 2026

GH-148273 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Apr 8, 2026
bitdancer pushed a commit that referenced this pull request Apr 8, 2026
…() (GH-115259) (#148273)

Original patch by gigaplastik, extended with a few more tests.

Addresses gh-70039 and bpo-25852: failure of starttls if connect is called explicitly.
(cherry picked from commit 442f83a)

Co-authored-by: nmartensen <nis.martensen@web.de>
bitdancer pushed a commit that referenced this pull request Apr 8, 2026
…() (GH-115259) (#148272)

Original patch by gigaplastik, extended with a few more tests.

Addresses gh-70039 and bpo-25852: failure of starttls if connect is called explicitly.
(cherry picked from commit 442f83a)

Co-authored-by: nmartensen <nis.martensen@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants