How to test SMTP servers on the command line
Using the telnet utility, it’s possible to directly connect to and test SMTP servers from the command line.
Encoding authentication details in base64
If your SMTP server requires authentication, you’ll need to use a base64-encoded version of your username and password strings. These can be generated by using an online base64 encoder, using PHP’s ‘base64_encode()‘ function:
<?php
echo base64_encode('some_text_to_encode');
?>
... piping plain text into the command line ‘base64‘ utility (if you’re on a Macintosh, you can install base64 with MacPorts):
echo 'some_text_to_encode' | base64
... or by piping plain text into a perl script:
echo 'some_text_to_encode' | perl -e 'use
MIME::Base64 qw(encode_base64);print
encode_base64(<>);'
Connecting to the SMTP server and sending a message
To launch telnet and initialize the connection to port 25, enter the following in a new Terminal window (substituting ’smtp.mailservername.com’ with your mail server’s address):
telnet smtp.mailservername.com 25
Once the connection has been established, enter:
HELO mailservername.com
If you need to authenticate on this SMTP server, enter the following command. If not, skip ahead to the ‘MAIL FROM:’ command:
AUTH LOGIN
You will be prompted in base64 to enter your username followed by your password, both of which should be entered in their encoded form as detailed at the start of this article.
After entering your username and password, enter the email address the message originates from:
MAIL FROM:willem@othermailservername.com
... followed by the email address the message will go to:
RCPT TO:willem@mailservername.com
Next, enter your subject and message body in this format:
DATA
Subject:This is my subject line
This is my message.
To finalize the content and send the message, break to a new line, enter a full stop ('.'), then break to a new line again.
If you don’t wish to send any further messages, enter this command to disconnect from the server:
QUIT