📄️ Overview
In Stalwart SMTP Server, a "session" refers to a single incoming SMTP connection. Each SMTP session progresses through a series of distinct stages, each with its own distinct function and relevance. The stages of an SMTP session include the following:
📄️ Connect stage
The connect stage is the initial stage of an SMTP session, where the server and client establish a connection. This stage is used to set up the initial parameters of the session, such as the hostname and greeting message.
📄️ EHLO stage
The EHLO (Extended Hello) is sent by an email client to the server to initiate an SMTP session and negotiate the features and extensions that will be used during the session. The EHLO command provides a way for the email client to identify itself, and for the server to advertise the capabilities and extensions it supports, such as authentication mechanisms, message size limits, and others. The response to the EHLO command provides information to the client about the server's capabilities, which the client can then use to determine the best way to send the email.
📄️ MAIL stage
The MAIL FROM command is used to initiate an SMTP message transfer by identifying the sender of the message. After the MAIL FROM command is issued, the receiving mail server checks the validity of the sender email address and ensures that the sender is authorized to send messages on behalf of that domain. If the sender email address is deemed valid, the message transfer process continues and the next command is issued to specify the recipient email address using the SMTP RCPT TO command.
📄️ RCPT stage
The RCPT TO command is a used to specify the recipient of an email message during the SMTP message transfer. It is used in conjunction with the MAIL FROM command, which specifies the sender of the email. After the RCPT TO command is issued, the SMTP server responds with a status code indicating whether the recipient is valid and whether it is willing to accept the email message for that recipient. If the recipient is valid and the server is willing to accept the email, the SMTP client can then proceed to send the email message using the DATA command.
📄️ DATA stage
The DATA command is used to initiate the data transfer phase of the email delivery process. Once the sender of the email has successfully completed the MAIL FROM and RCPT TO commands, they can issue the DATA (or BDAT when chunking is used) command to begin transmitting the email message. Once the entire email message has been transmitted, the SMTP server will respond with a status code indicating whether the message was accepted or rejected for delivery.
📄️ AUTH stage
The AUTH command is used to authenticate a user who wants to send an email message through an SMTP server. The AUTH command initiates the authentication process, after which the client must provide their credentials for authentication using SASL.
📄️ Throttling
Throttling refers to limiting the rate at which requests or data are processed by a system, in order to regulate its workload and avoid overloading the system. Concurrency limiting and rate limiting are two techniques used in Stalwart SMTP to control the amount of incoming traffic, ensuring that the server operates efficiently and remains protected from malicious activity.