SMTP stands for Simple Mail Transfer Protocol, a fundamental email protocol. SMTP is dedicated to the simple, efficient electronic mail transfer between servers.
When is SMTP used?
SMTP is the standard email protocol and is widely used for corporate and personal email systems. It works behind the scenes whenever you send an email via popular email clients or web-based services like Gmail or Yahoo Mail.
The process begins when a user sends an email. The email client (a Mail User Agent or MUA) uses SMTP to communicate with its configured outgoing mail server (an SMTP server or Mail Transfer Agent - MTA). The SMTP session is initiated with a 'handshake' between the client and the server. This usually involves the client sending a command like HELO or EHLO to introduce itself to the SMTP server.
Sending email information
Once the handshake is successful, the email client sends the email's metadata using SMTP commands. This includes the sender's email address (MAIL FROM command), the recipient's email address (RCPT TO command), and other necessary headers.
Transmission of the email content
The email client issues the DATA command, signaling that it is about to send the message body. The actual message data, including the subject and body of the email, is transmitted. In cases where the email includes attachments or non-ASCII text, these are encoded appropriately (often using MIME - Multipurpose Internet Mail Extensions) so they can be transmitted over SMTP.
Routing and delivery
The email is directly transferred to the recipient’s mail server if the sender and recipient are on the same domain. If they are on different domains, the SMTP server queries a Domain Name System (DNS) server to find the Mail Exchange (MX) record of the recipient's domain, which tells it where to forward the email. The sender's SMTP server then connects to the recipient's SMTP server (or an intermediate relay if necessary) and transfers the email.
Queue and retry mechanism
Suppose the recipient’s SMTP server is unavailable or busy. In that case, the sender’s SMTP server places the email in a queue and periodically retries sending it.
Final delivery and receipt by client
Once the recipient’s SMTP server accepts the email, it stores the message, usually in a queue. The recipient retrieves the email using an email client configured with a mail retrieval protocol such as IMAP or POP3.
After the transfer, the SMTP client sends a QUIT command to close the connection.
While SMTP is specifically designed for sending and relaying emails from the sender's server to the recipient's server, IMAP and POP are used for receiving and retrieving emails from a server to the user's email client. IMAP allows users to access and manage their emails directly on the server, enabling synchronization across multiple devices. On the other hand, POP typically downloads emails from the server to the user's device, often deleting the original from the server. In essence, SMTP handles the outbound dispatch of emails. In contrast, IMAP and POP govern those emails' inbound retrieval and local management.