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.
|