Recently, while reading upon mailboxes I was intrigued about the SMTP protocol, and tried to understand how it works.
The Simple Mail Transfer Protocol
The Simple Mail Transfer protocol is responsible for sending email from a sender’s email address to a recepient, by connecting through multiple MTAs in order to find the right mailbox to transfer email to.
Since SMTP is a client-based protocol, it uses DNS to find the right IP to send emails to.
Playing around with a simple SMTP Server
We can use the following python command to create a simple SMTP server on port 2525
.
The command doesn’t return any output once the server is started.
Now we use telnet to connect to the SMTP server using the command:
- The
HELO
command is responsible for letting the SMTP server know that an email message is incoming - The
MAIL FROM
command mentions the sender’s mail address. - The
RCPT TO
command mentions the receiver’s mail address. - The
DATA
command refers to ASCII encoded data, that is going to follow it and needs to be terminated by an empty line and a .(dot) which is what theEnd data with <CR><LF>.<CR><LF>
is. - Similar to HTTP, 2XX status codes are positive 3xx codes are positive intermediate, 4XX are negative.
- Particularly
220
refers to<domain> Service Ready
,250
refers torequested mail action okay, completed
. The list of all status codes can be found here.