How to test a mail server from the command line

Posted on Fri 06 January 2017 in linux • 1 min read

As I am currently setting up a new mail server, I had to test the new server manually (As of now, the DNS records are not changed, so mail clients are problematic).

If you want to test plain text ports like standard postfix, go simply with telnet localhost 25. If you try this remotely from home (on the public interface), you will be kicked out by the server, because usually IP-ranges from ISPs for dynamic allocations are blocked. So use this directly on your server or from another server. Common things like helo and ehlo might work, but 'sending' mail without authentication should fail, even for adresses the server is responsible for.

The other part is the SMTP submission, which should be on port 587 for STARTSSL. This service is used by the mail client to send mails, therefore it is usually required to use encryption (test this with telnet and check if auth is allowed). Doing encryption with telnet is not possible, so use openssl for STARTTLS in this case:

openssl s_client -starttls smtp -crlf -connect

After that usage is as with the telnet client on port 25, but for sending mail you must authenticate yourself. For plain auth, use

auth plain [user/pass string]

with the user and password string generated with

perl -MMIME::Base64 -e 'print encode_base64("\000user\\000password");'

Note that @ has to be escaped and the \000 must remain in place.

See for example this Microsoft site for possible SMTP commands: