
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 1.2.3.4 (where 1.2.3.4 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 1.2.142.8... 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 [2.25.35.3] 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: 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).
Comments