How to test postfix through telnet

Telnet basics

Telnet is the most basic mail client. It does the same thing as the bigger clients you use on your workstation (such as Thunderbird, Outlook, Mail, etc) – it sends mail.

However, instead of being wrapped in a nice GUI it is a command line tool that can be used to diagnose our postfix installation (and to send mail!).

This is a primer for telnet. I won’t be going into great detail of the why’s and the how’s of every aspect of telnet and the responses we (should) receive.

Setting up mail servers can be a complicated issue and there are some incredible large and detailed tomes and manuals available for those who need to get into the minute detail.

However, following the articles will allow you to understand the basics and know what to look for should you want more detail.

Email details

When you send an email you can use the analogy of physically posting a letter:

You greet the postman. You hand over the envelope which should have the address (recipient) and the sender’s address – inside the envelope will be the actual letter, or the data.

Going with that analogy, we need a way of authenticating or confirming all those details.


We’ll start of the sequence by connecting to the mail server and greeting the postman.

On the Slice enter:

telnet 25

This starts the telnet session on port 25.

You should receive a 220 response:

Trying Connected to localhost. Escape character is '^]'. 220 ESMTP Postfix (Ubuntu)


Next we can greet the postman:


Note the test subdomain doesn’t exist – it is simply a way of greeting the mail server.

The mail server should respond with a confirmation of who it is:



Now we have greeted the postman and got the correct responses we can start to fill out the envelope for our letter.

We start by letting the server know who the sender is:


If the mail server accepts the sender address, you will get another ‘250’ output:

250 2.1.0 Ok


Now we can sort out to whom we are sending the letter:


We are hoping for a 250 response:

250 2.1.5 Ok

Again, good news.

You can add more recipients – unlike a physical letter, the same email can be sent to multiple recipients.


Now we come to the ‘meat’ of the letter: the data.

To start the main body of the message:


The response is fairly sparse:

354 End data with <CR><LF>.<CR><LF>

Now you need to enter the subject and the body.

Note you need to physically type the word ‘Subject:’

Subject: test message

Press enter/return and then you can type the body of the message:

This is the body of the message!

As when we used the ‘mail’ command in a previous article, we need to enter a single period (.) to indicate we have finished the body of the message.

As before, we are rather hoping for a 250 response:

. 250 2.0.0 Ok: queued as 9620FF0087



Well, we’re done with telnet for the moment so we can quit:


This will dump you back at the bash prompt:

221 2.0.0 Bye Connection closed by foreign host. You have new mail in /var/mail/demo


I have new mail in /var/mail/demo

You have mail

Let’s use the ‘tail’ command to read the end of the mail file:

tail -n 15 /var/mail/demo

That particular command parses the last 15 lines of the /var/mail/demo file (which is where our mail is kept).

If you don’t see all of the mail as shown below, you can adjust the number of lines to, say, 20.

In my case, the output was as follows:

From Wed Aug 6 10:33:20 2008 Return-Path: <> X-Original-To: Delivered-To: Received: from (localhost []) by (Postfix) with SMTP id 9620FF0087 for <>; Wed, 6 Aug 2008 10:28:43 +0000 (UTC) Subject: test message Message-Id: <> Date: Wed, 6 Aug 2008 10:28:43 +0000 (UTC) From: To: undisclosed-recipients:; This is the body of the message!

Well that’s pretty cool.


It goes without saying (even though I am going to say it) that there is far, far more to it than the basics shown above.

It is simply impossible to go into all the details of what is possible with email headers and messages, encodings and the details of telnet.

However, this introduction should show how mail works and what steps are taken when mail is sent and received.

Perhaps you can begin to see why some legitimate mail may be seen as spam email – if any of the steps above failed or gave the wrong response then warning flags are raised.

A wrong hostname will mean mail sent from the Slice does not identify itself properly. Improperly formatted addresses or message bodies can raise eyebrows and flags.


Telnet is a very simple mail client and can be used to diagnose our postfix install.

Controlled via the command line we can see if the responses from our installation are correct.

Once done, we were then able to read our mail.

Although that is well and good, it would be a bit of a annoyance having to read our mail from the command line. As such, we will look at pop and imap access in later articles.