aio-libs / aiosmtpd

A reimplementation of the Python stdlib smtpd.py based on asyncio.
https://aiosmtpd.aio-libs.org
Apache License 2.0
312 stars 95 forks source link

[Question] EHLO response in a single packet? #389

Open Salvoxia opened 7 months ago

Salvoxia commented 7 months ago

Hi,

I'm going out on limb here and I don't expect much to come from this, but I'd figured I give it a shot anyway.

I need a really dumb application to send emails to another application using aiosmtpd as the SMTP server component (Mailrise), and that dumb application seems to have problems establishing a proper conversation with aiosmtpd. When testing with an SMTP server my hoster provides, it seems to work fine. So I fired up Wireshark to capture the communication in both cases and find differences. The working example looks like this: smtp_Working

Take a closer look at the EHLO repsone: singlePacketEHLOReply The way I interpret this is that the server lists all of its capabilities in a single packet. The client determines that STARTTLS is supported and continues to initialize a TLS connection. All good so far.

Now here's the conversation with aiosmtpd: aiosmtpd In response to the client's EHLO a bunch of 250 replies are sent, listing all the server's capabilities, this time as separate packets. However, as soon as the second 250 repsonse is received, the dumb client seems to fall back to HELO. While the server is still sending its capabilities, the client seems to interpret each 250 response as an OK to go ahead with sending the mail. Now client and server are out of sync, the client dumps the mail payload while the server is not ready, and the client thinks everything went fine and terminates the connection while the server just finished listing its capabilities.

Of course the actual problem here is with the dumb client application rushing the conversation and not waiting for the server to finish. But it looks like its working if the EHLO repsonse is a single packet.

Does my interpretation sound correct? And if so, is there a way for aiosmtpd to bundle the complete EHLO response in a single packet as well? I realize all of this is not actually a problem for you, since I'm dealing with an SMTP client that doesn't seem to play by the rules 100% correctly, but I figured I'd give it a try and task :)

Any comment is much appreciated!

Best Regards, Salvoxia