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 “afzalkhan@mail.com” | openssl enc -base64 -e
c2lkZGhlc2hAbWFpbC5jb20=
[root@afzalkhan ~]# echo -n “test123test” | openssl enc -base64 -e
dGVzdDEyM3Rlc3Q=

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 test.mail.com 25
Trying 10.10.10.10…
Connected to mail.com (10.10.10.10).
Escape character is ‘^]’.
220 ESMTP mail
ehlo afzalkhan.com          [EHLO is just like HELO to except that the server’s response]
250-mail.com
250-PIPELINING
250-SIZE 25480000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH LOGIN Y29tcGxpYW5jZUBhbnRpcXVlbGltaXRlZC5jb20= [Encrypted username]
334 UGFzc3dvcmQ6
QXNibCoxMjM=             [Encrypted Password]
235 2.7.0 Authentication successful    [Authenticated Successfully]
MAIL FROM: afzal khan@test.com  [From id from which you want to send test mail]
250 2.1.0 Ok
RCPT TO: test@gmail.com  [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 mail.com 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 ~]#

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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