What is SMTP?
Getting to know the simple mail transfer protocol a little more.
Recently, while reading upon mailboxes I was intrigued about the SMTP protocol, and tried to understand how it works.
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
$ sudo python3 -m smtpd -n -c DebuggingServer localhost: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:
$ telnet localhost 2525
Trying ::1... Connected to localhost. Escape character is '^]'. 220 pop-os.localdomain Python SMTP proxy version 0.3 HELO shrirambalaji.dev 250 pop-os.localdomain MAIL FROM: firstname.lastname@example.org 250 OK RCPT TO: email@example.com 250 OK DATA 354 End data with <CR><LF>.<CR><LF> Hello World from SMTP! . 250 OK
HELOcommand is responsible for letting the SMTP server know that an email message is incoming
MAIL FROMcommand mentions the sender's mail address.
RCPT TOcommand mentions the receiver's mail address.
DATAcommand 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 the
End data with <CR><LF>.<CR><LF>is.
- Similar to HTTP, 2XX status codes are positive 3xx codes are positive intermediate, 4XX are negative.
<domain> Service Ready,
requested mail action okay, completed. The list of all status codes can be found here.