Test Your SMTP Mail Server via Telnet

Problem
You have configured an outgoing email server, and you want to make sure it’s working correctly.

tl;dr
From command line/shell in any OS that has Telnet feature installed:

Solution

All mail servers have a nifty feature where they can relay mail forward. In the early days of the Internet, way before the world wide web even existed, this used to be how email operated – you would connect to an email server via Telnet, and from there you were able to compose a message and send it forward, without ever having to verify your identity. As can be imagined, this was not a very good model as email became more and more ubiquitous. First spammers were just that – automated scripts that would mass send an email from an unsecured relay server. Since then, the feature was significantly overhauled and secured, though it has not been taken out entirely.

Modern mail servers, such as Zimbra or Microsoft Exchange only allow you to send mail within their own domain. If, for example, your domain is example.net, you can only relay mail within the example.net domain. However, this is enough to test your domain and SMTP configuration.

Connect to the mail server with Telnet

To do so, you need to Telnet in to your mail server on port 25 (SMTP). Keep in mind that backspace (<--) does not play well with Telnet. If you make a mistake, your best bet is to just hit enter and re-type in the command. Assuming your mail server's FQDN is mail.example.net:

This should give you your mail server’s greeting, such as:

From there on, you need to introduce yourself via the helo or ehlo command:

Don’t worry too much about your hostname. It is used by the mail server to determine where the email message is coming from, although the server has no way of verifying it. Even something like ehlo cat works fine. If the greeting was successful, you should see the server’s list of options:

Send a test message

From here you should be able to send a quick test message to make sure the server works. Generally, any off-the-shelf product such as Exchange or Zimbra will only allow you to send a message within your own domain, or with any email address, but only from an IP address within the same subnet. However, it works whether an email address exists or not. So, do this:

Assuming the mailbox 123test@example.net is made up, but the mailbox vlad@example.net is real, the message should still show up in user Vlad’s mailbox. Now, type in data, followed by the actual message:

When you are done composing the message, hit Enter to create a new line, type in a “.” (period), and hit Enter again to send it:

You should see a “message queued for delivery” notification:

From here, you should see the message in Vlad’s mailbox.

Relay access denied

If you try to send an email outside the allowed domains, or from an IP from which relaying (aka sending a message generated elsewhere) is not allowed, you may see a message similar to the ones below:

This means you are trying to send a message outside the domain allowed by the server. This is done to prevent spam.

Author

Vlad Dzhabarov