Categories
Exchange

How to Authenticate to SMTP server via Command Line

Recently I had to prove to an application admin that the user he was using to send SMTP email was able to authenticate and properly send email via SMTP. The easiest way to prove that this was a configuration issue with the application and not a SMTP issue was to do it from the server via command line.

Steps to send SMTP email and authenticate:

Telnet to server on port 25

telnet servername 25

Type EHLO

EHLO
250-servername.domain.com Hello [10.149.1.55]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK

This is were it got interesting. It seems that an SMTP server asks and expects answers in Base64. For example, "VXNlcm5hbWU6" in Base64 means "Username:" and "UGFzc3dvcmQ6" means "Password:"
You can find a few Base64 encoders/decoders on the need just by googling it, I used makcoder.sourceforge.net/demo/base64.php.

So in order to authenticate to the SMTP server you will need to encode the username and password to Base64:
"Username" = "VXNlcm5hbWU="
"Password" = "UGFzc3dvcmQ="

Now to auth to the server:

Type AUTH login

AUTH login
334 VXNlcm5hbWU6

Enter the Base64 username and press enter:

VXNlcm5hbWU=

Next enter the Base64 password followed by enter

334 UGFzc3dvcmQ6
UGFzc3dvcmQ=
235 2.7.0 Authentication successful.

This shows that the user was able to authenticate and then all that’s next is to send a test email and then confirm that the mailbox recieved it

MAIL FROM: username@domain.com
250 2.1.0 username@domain.com….Sender OK
RCPT TO: username@domain.com
250 2.1.5 username@domain.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
This is a test SMTP email from application server
.
250 2.6.0 <servernameLrLySMy00000002@servername.domain.com> Queued mail for delivery

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.