A network protocol is a set of rules that computers must follow to change the information in a network. Network protocols that operate on the Internet are part of the suite of Internet protocols. Unlike most Internet protocols that need to be explained at the network packet level, email protocols are simple command/response protocols that can be understood and easy to handle.
SMTP (Simple Mail Transfer Protocol) is a simple text protocol based on a command/response communication. The email source sends an order to the destination and awaits a response from it. SMTP uses the TCP 25 port. The application security chapter features three mailing agents: Sendmail, Qmail and Postfix, and two protocols for POP3 and IMAP e-mail access. Sendmail was the first e-mail management application. Although the first versions have not been designed with a focus on security, the later versions have taken a step forward by implementing multilateral defense against unsolicited commercial messages and incorporating support for SMTP authentication.
The competition to Sendmail is Qmail, which aims to solve the security problems in Sendmail by offering a targeted MTA with a focus on security.
The rules followed by Qmail are: avoiding running the email daemon as root, preventing setuid use, addressing addresses differently from programs and files. Sendmail was one of the first programs to implement this protocol. Since 2001, at least 50 applications have been deployed that deploy SMTP (both servers and clients). Among the most popular SMTP servers are Postfix, qmail, Novell GroupWise, Novell NetMail and Microsoft Exchange Server.
SMTP creates a connection between the source and the destination of the email. The protocol does not refer to how the message to be transmitted is passed from the user to the SMTP client, or how the message received by the SMTP server is delivered to the receiving user, and how the message is stored or how many times the SMTP client tries to send the message.
The TCP protocol is used to create and run the connection, and to ensure that the tremendous information at the destination arrives sequentially and without mistakes. The data flow contains both the SMTP commands and the actual message.
Communication between the client and the server is done through ASCII texts. The client initially establishes the connection to the server and expects the server to respond with the “220 Service Ready” message.
After receiving the 220 code, the client sends the HELO command indicating their identity. In some older systems, the EHLO command is sent, the EHLO command indicating that the sender of the message can process the service extensions and wants to receive a list of the extensions that the server supports.
After the communication is started, the client sends messages, ends the connection, or can use the services provided by the server, such as checking the email addresses. The server must respond after each command indicating whether it has been accepted if orders are still expected, or there are errors in writing these commands.
To send a message, use the MAIL command to specify the client address. If this command is correct, the server will respond with the “250 OK” message.
The client then sends a series of RCPT commands specifying the recipients of the message.
The server will respond with “550 No such user here“, or “250 OK“, depending on the correctness of the received order.
Once the recipients are specified, and the server accepts the commands, the DATA command is sent, through which the server is notified that the sender will start writing the message content. The server can respond with the message “503 Command out of sequence” or “554 No valid recipients” if it did not receive the MAIL or RCPT commands or these commands were not accepted.
If the server responds with the “354 Start mail input” message, the client will be able to enter the text of the message. The end of the message is marked with <CR> <LF>. <CR> <LF>.
Any SMTP command receives a reply. Most of the time, error codes are not visible to the user. Email programs are the ones that process these messages.