[New-bugs-announce] [issue42498] smtplib is glitchy after receive server code 500

izomiac report at bugs.python.org
Sun Nov 29 00:30:35 EST 2020


New submission from izomiac <izomiac at zrwb3.r-66y.com>:

I use a custom e-mail server and noticed I wasn't getting e-mails from FreeNAS.  I tracked the bug down to Python's smtplib.  My home internet can't do outbound port 25, so I use a port forwarding script that I've since learned injects "PROXY TCP4 <client ip> <server ip> <client port> <server port>\r\n".  This isn't a basic SMTP command, so my server responds with "500 Syntax error, command unrecognized\r\n".  

The first glitch in smtplib is that it assumes the server has precognition and upon receiving the syntax error assumes that the *next* command smtplib sends is invalid.  This happens to be "ehlo". After assuming "ehlo" got an error it backs down to "helo".  My server didn't like clients to send two greetings so it responded with "503 Bad sequence of commands", but allowed the connection to proceed anyway after the mild scolding.  smtplib proceeds to issue a "mail FROM" command, then a "rset" command and disconnects in shame after reflecting upon its actions for a while.

So, I modified my server to be a bit more laid back and just accept two greetings.  smtplib proceeds to issue "mail FROM", "rcpt TO", and "data" commands before crashing (raising an "SMTPDataError" in the traceback).

I then modified my server to ignore "PROXY" commands rather than send a syntax error and everything worked perfectly.  I don't code in python, and obviously my SMTP server is a one-off creation, but I figured I ought to let you all know in case you want to make some improvements to smtplib to better follow the SMTP spec and not crash with a cryptic error message three commands later after receiving a non-fatal error message.

----------
components: email
files: debug output.txt
messages: 382038
nosy: barry, izomiac, r.david.murray
priority: normal
severity: normal
status: open
title: smtplib is glitchy after receive server code 500
type: crash
versions: Python 3.7
Added file: https://bugs.python.org/file49634/debug output.txt

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42498>
_______________________________________


More information about the New-bugs-announce mailing list