>
What will I learn?
SMTP (Simple Mail Transfer Protocol)
What is SMTP?
SMTP, or Simple Mail Transfer Protocol, is a communication protocol that enables the exchange of email between one client and another. This protocol governs how email clients and servers communicate during the transmission of email messages.
It is essentially a set of rules that dictates the sending, routing, and relaying of email messages from the sender to the recipient’s email server. It works as a push protocol, where it initiates the communication from the client side to the server, unlike protocols such as IMAP or POP3, which are used to retrieve emails at the recipient end.
What does SMTP do?
There are three key functions that SMTP does to enable email transmission:
- Message submission: SMTP submits the email message from the client to the sending email server.
- Message transmission: SMTP allows the delivery of the email message from one server to another across the Internet.
- Message queuing and retrying: If for temporary reasons a message cannot be delivered, SMTP adds the message to a queue and retries delivery until successful or a maximum attempts threshold is reached.
Common SMTP commands
Command | Description |
HELO/EHLO | Initiates the first communication from the client to the server |
MAIL FROM | Specifies the sender's email address |
RCPT TO | Specifies the recipient's email address |
DATA | Comprises the message content |
RSET | Resets the current communication (session) |
QUIT | Ends the SMTP session |
How does SMTP work?
- Client-server connection
The email client sending the message will connect to the SMTP server. - First contact (handshake)
The EHLO or HELO command is used to begin the session. - Mail envelope creation
The SMTP now builds the mail envelope where it informs the server who the sender is and where the email should go. This is done using the MAIL FROM and RCPT TO commands. - Message transmission
Using the DATA command, SMTP conveys the content of the email to the email server to relay. - Message relay
SMTP also helps locate the recipient server to relay the message. - End session
Once all of the data is transferred, the communication line/session is ended using the QUIT command.