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 184.108.40.206 (where 220.127.116.11 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");' asadBlqewrQEFGNvbQ== perl -MMIME::Base64 -e 'print encode_base64("MyP@\$\$w0rd");' TXEEWTQkdzByZA==
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 Trying 18.104.22.168... 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 [22.214.171.124] 250-SIZE 52428800 250-8BITMIME 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
We now issue the AUTH LOGIN command and then send it the base64 encoded versions of our username and our password:
AUTH LOGIN 334 VXNlcm5hbWU6 asadBlqewrQEFGNvbQ== 334 UGFzc3dvcmQ6 TXEEWTQkdzByZA== 235 Authentication succeeded mail from: firstname.lastname@example.org 250 OK rcpt to: email@example.com ....
If login succeeds then we can continue our mail transaction as per normal (mail from: sender; rcpt to: receiver; data, etc).