The Simple Mail Transfer Protocol (SMTP) is an application layer communication protocol for email. It defines the communication between mail servers (which store outgoing/incoming messages) and is built on persistent TCP on port 25 to reliably transfer messages. SMTP sends multiple objects in a multipart message. A direct transfer is from a sending server to receiving server.
It is a “push protocol”, i.e., it is only used to send messages between servers or from a user agent to a mail server. To receive messages, we must use IMAP or HTTP.
Communication
The basic procedure is as follows:
- A sender uses their user agent to compose a message and send it to a specific email address.
- This user agent sends to a mail server, where the email is placed in a message queue.
- The client mail server sees the message in the queue. It opens a TCP connection to the SMTP server for the receiver’s address.
- After SMTP-specific handshaking, the client sends the message via TCP.
- The server receives the message, and places it in the receiver’s mailbox.
- The receiver uses their user agent to check the receiver server mailbox.
Client commands:
HELO— used by the client to identify itself.MAIL FROM— indicates the email address source.RCPT TO— indicates the email address destination.DATA— command is sent to indicate that data will start flowing.QUIT— indicates that the client server is done, and the TCP connection can be closed.
Messages
Like HTTP, it follows a command/response interaction in 7-bit ASCII. Responses have a status code and phrase. The message must also be in 7-bit ASCII (not ideal for multimedia data). A message that consists of a \r\n . \r\n (no spaces, carriage return, line feed, CRLF), i.e., a single dot on a line, determines the end of the message.
What happens if the mail message has a single dot on a line? • If the first character of the line is a period, SMTP inserts one additional period at the beginning of the line. • In a received message: • If the line is composed of a single period, it is treated as the end of mail indicator. • If the first character is a period and there are other characters on the line, the first character is deleted.