How to test SMTP connection from CLI

Posted: August 7, 2013 in Uncategorized

As a technical person sometime you need to test your SMTP authentication and mailing flow to make sure everything is working fine. But instead of searching for email client for sending test mail you can do the same testing from command line prompt. First of all we need to encrypt username and password of your SMTP login. Keep in mind that we don’t want to access web browser while doing this test so we have to do encoding from command line prompt.

1. Using openssl cryptography toolkit we can do base64 encryption.

[root@afzalkhan ~]# echo -n “” | openssl enc -base64 -e
[root@afzalkhan ~]# echo -n “test123test” | openssl enc -base64 -e

So we encrypted username and password that we gonna use for SMTP authentication

2. Now connect to your mail server on 25 port using smtp

[root@afzalkhan ~]# telnet 25
Connected to (
Escape character is ‘^]’.
220 ESMTP mail
ehlo          [EHLO is just like HELO to except that the server’s response]
250-SIZE 25480000
250 DSN
AUTH LOGIN Y29tcGxpYW5jZUBhbnRpcXVlbGltaXRlZC5jb20= [Encrypted username]
334 UGFzc3dvcmQ6
QXNibCoxMjM=             [Encrypted Password]
235 2.7.0 Authentication successful    [Authenticated Successfully]
MAIL FROM: afzal  [From id from which you want to send test mail]
250 2.1.0 Ok
RCPT TO:  [Recipient id to which mail will get deliver]
DATA                       [Type data to enter test word in body]
354 End data with <CR><LF>.<CR><LF>
this is a test email  [Type your test message]
.                                 [Type “.” to send your message]
250 2.0.0 Ok: queued as 761761C01C5  [Queue id of message is 761761C01C5]
quit                           [Type quit to close the connection]
221 2.0.0 Bye
Connection closed by foreign host.
[root@afzalkhan ~]#


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s