On my last post I talked about the new async simplemail-qt API that I wanted to add, yesterday I finished the work required to have that.
SMTP (Simple Mail Transfer Protocol) as the name says it’s a very simple but strict protocol, you send a command and MUST wait for the reply, which is rather inefficient but it’s the way it is, having it async means I don’t need an extra thread (+some locking) just to send an email, no more GUI freezes or an HTTP server that is stalled.
The new Server class has a state machine that knows what reply we are waiting, and which status code is the successful one. Modern SMTP servers have PIPELING support, but it’s rather different from HTTP PIPELING, because you still have to wait for several commands before you send another command, in fact it only allows you to send the FROM the RECIPIENTS email list and DATA commands at once, parse each reply and then send the mail data, if you send the email data before you are allowed by the DATA command the server will just close the connection.
So in short we only save a few (but important) round trips, this new version also includes support for the RESET command, this is useful for example when you have a long list of emails, and some of them have malformed RECIPIENTS email, you will get an error for the command but instead of closing the connections and start the long SMTP handshake you just RESET and try to send the next email.
Cutelyst master is already using this new class if you set ViewEmail::setAsync(true);. With that set you won’t get the SMTP mail queued reply but will still be able to process more HTTP requests while waiting for the SMTP reply.
I plan to do a 2.0.0 stable release in the following weeks so if you use this library please test and suggest API changes that you may like.