Skip to content

smtplib.SMTP should reset internal 'helo' and 'ehlo' state within 'connect()' #85642

Description

@Dadeos
mannequin
BPO 41470
Nosy @warsaw, @bitdancer, @websurfer5

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 = None
closed_at = None
created_at = <Date 2020-08-04.09:39:24.082>
labels = ['type-bug', '3.8', 'expert-email']
title = "smtplib.SMTP should reset internal 'helo' and 'ehlo' state within 'connect()'"
updated_at = <Date 2020-08-05.23:25:36.525>
user = 'https://bugs.python.org/Dadeos'

bugs.python.org fields:

activity = <Date 2020-08-05.23:25:36.525>
actor = 'Jeffrey.Kintscher'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['email']
creation = <Date 2020-08-04.09:39:24.082>
creator = 'Dadeos'
dependencies = []
files = []
hgrepos = []
issue_num = 41470
keywords = []
message_count = 1.0
messages = ['374798']
nosy_count = 4.0
nosy_names = ['barry', 'r.david.murray', 'Jeffrey.Kintscher', 'Dadeos']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41470'
versions = ['Python 3.8']

Linked PRs

Activity

  1. Dadeos commented on Aug 4, 2020

    Dadeosmannequin
    MannequinAuthor

    Attempting to reuse an instance of 'smtplib.SMTP', via invocation of the 'smtplib.SMTP.connect(…)' function, results in an invalid SMTP command sequence being issued to the connected server:

    import smtplib
    
    smtp = smtplib.SMTP()
    smtp.connect('smtp.gmail.com')
    smtp.ehlo_or_helo_if_needed()
    smtp.close()
    try:
        smtp.quit()
    except smtplib.SMTPServerDisconnected:
        pass
    smtp.connect('smtp.gmail.com')
    print(smtp.mail('user@example.com'))
    

    results in "(503, b'5.5.1 EHLO/HELO first. … - gsmtp')"

    The values stored in 'self.helo_resp' and 'self.ehlo_resp', as considered within 'smtplib.SMTP.ehlo_or_helo_if_needed()' [1], should be reset to a value of 'None' upon successfully establishing a new connection to a server. The correct sentiment is expressed within 'smtplib.SMTP.quit()' [2] but this resetting of state should be performed upon establishing a new connection rather than termination of an old connection. Whilst the simplified example provided is arguably an invalid use of the 'smtplib.SMTP' library the scenario can occur, specifically when the initial connection is unilaterally terminated by the server, which makes the reset logic provided in 'smtplib.SMTP.quit()' inaccessible due to the 'smtplib.SMTPServerDisconnected' exception raised as a consequence of attempting to execute an SMTP 'QUIT' command over a disconnected socket.

    [1]

    if self.helo_resp is None and self.ehlo_resp is None:

    [2] https://github.com/python/cpython/blob/da51ba442c7bf717872633676207c1ae10e99c99/Lib/smtplib.py#L989L990

  2. transferred this issue fromon Apr 10, 2022
  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions