Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

smtplib: missing case in handling 421 response in sendmail #132796

Open
Labels
3.13bugs and security fixes3.14bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@codeZeilen

Description

@codeZeilen

Bug report

Bug description:

Thesendmail function in smtplib does a good job of handling 421 responses from SMTP servers but is missing one case. This may lead to SMTP client connections not being closed properly.

Background

SMTP servers can send 421 responses whenever they need to shut down the connection (RF 5321 3.8). Clients should take care of closing the connection when receiving a 421.

Details

Thesendmail function combines the low-level SMTP commands into a full session for sending some text content via SMTP. The function needs to handle 421 responses, as any single command may return a 421 response. The function already handles almost all cases but is missing one for the call of thedata function, which does its own response code checking and mayraise an exception.

Test to reproduce

The test was derived from the correspondingrosetta-test SMTP test suite and adapted to the smtplib test infrastructure.

deftest_421_during_data_cmd(self):smtp=smtplib.SMTP(HOST,self.port,local_hostname='localhost',timeout=support.LOOPBACK_TIMEOUT)smtp.noop()self.serv._SMTPchannel.data_response='421 closing'withself.assertRaises(smtplib.SMTPDataError):smtp.sendmail('John@foo.org', ['Sally@foo.org'],'test message')self.assertIsNone(smtp.sock)self.assertEqual(self.serv._SMTPchannel.rcpt_count,0)

CPython versions tested on:

CPython main branch, 3.10, 3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp