Test an SMTP server from commandline using telnet
- 31 Oct 2018: Post was created (diff)
Whenever I look at protocols I always get positively surprised at how easy they are to understand once you take an actual look at it.
This time around I wanted to test an SMTP server without the need to set up some random test client software or putting something together in Python or Node.js. This time, I wanted something plain simple.
telnet is a tool that is very handy in talking with servers. No magic goes on under the hood. Perform simple conversations from a client to a server.
To connect to a server on the default plain-text SMTP port (25) you can
telnet target.host.example.com smtp and start the conversation.
Below is an example transmission of sending an email over SMTP. All lines
starting with three numbers are responses from the server.
QUIT are commands written and sent from the client
to the server.
$ telnet mail.example.com smtp Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 mail.example.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 22 Oct 2013 05:05:59 -0400 HELO myserver.no 250 myclient.hostname.example.no Hello myclient.hostname.example.no [127.0.0.1], pleased to meet you MAIL from: email@example.com 250 2.1.0 firstname.lastname@example.org... Sender ok RCPT to: email@example.com 250 2.1.5 firstname.lastname@example.org... Recipient ok DATA 354 Enter mail, end with "." on a line by itself Hey This is test email only Thanks . 250 2.0.0 r9M95xgc014513 Message accepted for delivery QUIT 221 2.0.0 mail.example.com closing connection Connection closed by foreign host.
The same as above with server replies and telnet output omitted:
HELO myserver.no MAIL from: email@example.com RCPT to: firstname.lastname@example.org DATA Hey This is test email only Thanks . QUIT
Now it’s easy to see how simple the SMTP protocol is.