So, you want to test an SMTP server’s functionality using Telnet? We’ll be discussing the ins-and-outs of connecting to an SMTP server via Telnet in this article, with some in-depth examples to guide you through. As always, I’ll keep this brief for your viewing comfort.
Connect to the SMTP server with Telnet
Open Terminal and initiate the connection to your desired SMTP server.
I’ll be using my local Exim mail server on port 25 as an example:
telnet localhost 25
If you would prefer to play around with an open SMTP server, I would suggest using your ISP’s.
If the handshake is successful, you should see a status code of 220 with a welcome message (depending on your SMTP server)
Connected to localhost. Escape character is '^]'. 220-localhost ESMTP Exim 4.77 #2 Sun, 30 Sep 2012 16:20:58 +1000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
Introducing Yourself with Telnet
Next, we’ll introduce ourselves using EHLO:
If all went to plan, you should receive a status code of 250:
250-localhost Hello drew 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
Before we proceed any further, I’d like to talk about the difference between EHLO and HELO.
EHLO (Enhanced SMTP) is the successor of HELO; EHLO prints the abilities of the SMTP server (as seen above) when connecting.
Logging in to your SMTP Server using Telnet
In order to login to your SMTP server, simply issue the following command:
If successful, your SMTP server will respond with a ‘username’ prompt (status code 334).
The username and password prompts are obfuscated, if you hadn’t noticed.
You will need to Base64 encode your username and password to proceed.
If you are using Mac OSX or Linux, this can be achieved via the pre-installed OpenSSL package. Alternatively, you can use the online Base64 encoder.
Open a new Terminal window and issue:
echo 'firstname.lastname@example.org' | openssl base64 && echo 'youremailpassword' | openssl base64
You should now see your username and password printed respectively.
Now copy & paste your Base64 encoded username, hit enter, then enter your Base64 encoded password from the terminal output.
Writing your First Email with Telnet
Now we can start structuring our email to be delivered via our SMTP server.
Firstly, we’ll let our SMTP server know who the mail is from:
MAIL FROM: email@example.com
Now, we can tell our SMTP server who the recipient is:
RCPT TO: firstname.lastname@example.org
Next, we can begin to format our email body.
To signify that we’d like to start formatting the email body, issue:
Okay, down to writing the email. To keep the confusion out of things, the MAIL FROM and RCPT TO fields we entered above are the tangible addresses, they will be housed within the email header and will depict where and who the email is sent to.
Begin writing your email body by filling in the FROM field:
Shortly after, enter the TO field:
Enter a subject for your message:
Subject: Hi, this is a test
You can now hit enter and start writing your email body as you see fit.
To signify that you have finished writing the email body, enter a single period ‘.’ on a single line, and hit enter.
If all went to plan, your SMTP server would have queued the email for delivery.
That’s it! If you have any suggestions, let me know in the comments below.