Testing SMTP Auth on the command line

While setting up an exim mail server you may want to log into the mail server to test sending an email from the command line, or you may want to do a test mail with exim -bh (where is any valid IP address.

In order to log into the SMTP server you need a base64 encoded version of your username and password.

To do that, on the command line you can generate these with a little perl script like this:

perl -MMIME::Base64 -e 'print encode_base64("john\@example.com");'

perl -MMIME::Base64 -e 'print encode_base64("MyP@\$\$w0rd");'

Ok, so now we have the base64 representation of our username and password. Do note that the @ symbol in the email address must be escaped, ie, \@.

We can now log into our server using telnet:

telnet mail.example.com 25
    Connected to mail.example.com.
    Escape character is '^]'.
    220 ubuntu-2gb-hel1-2 ESMTP Exim 4.86_2 Mon, 21 May 2018 06:35:42 +0200

Once we get the 220 response from our mail server we have to let it know that we want to authenticate. We do that by issuing the EHLO command with our own hostname (can be anything, but usually will be your own PC name):

ehlo john
    250-ubuntu-2gb-hel1-2 Hello john []
    250-SIZE 52428800
    250 HELP

We now issue the AUTH LOGIN command and then send itĀ the base64 encoded versions of ourĀ username and our password:

    334 VXNlcm5hbWU6
    334 UGFzc3dvcmQ6
    235 Authentication succeeded
mail from: john@example.com
250 OK
rcpt to: me@example.co.za


If login succeeds then we can continue our mail transaction as per normal (mail from: sender; rcpt to: receiver; data, etc).

Leave a Reply

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