Using Telnet to test Postfix
In a previous article, you sent test emails by using the command line. However, there was no real feedback from these clients about whether the mail server responded with the correct details. It is possible to send and receive email with details that are not entirely correct, which can cause issues later.
In this article, you use Telnet to check the server responses to mail requests.
Telnet can act as the most basic mail client. It can do the same thing as the other clients you use on your workstation, such as Thunderbird, Outlook, and Mail: it sends email. However, Telnet is a command line tool that you can also use to diagnose your Postfix installation.
Note: This article provides a simple primer for Telnet. It does not explain of every aspect of Telnet and the responses that you should receive. Setting up mail servers can be a complicated issue, and some detailed manuals are available for users who need minute details. However, following this article should enable you to understand the basics and know what to look for if you want details.
When you send an email, you can use the analogy of physically posting a letter at the post office: you greet the postal worker and you hand over the envelope, which should have the recipient’s address and the sender's address. Inside the envelope is the actual letter, or the data.
Using that analogy, you need a way of authenticating or confirming all those details.
The sequence starts by connecting to the mail server (greeting the postal worker).
On the mail server, enter the following command, which starts the Telnet session on port 25:
telnet mail.democloud.com 25
You should receive a 220 response, as shown in the following example::
Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 mail.democloud.com ESMTP Postfix (Ubuntu)
Note: If you can't use Telnet to open port 25, try modifying your Postfix master.cf file to allow port 587 communication, as well as opening 587 in iptables. Some Internet providers block users from accessing port 25.
Now you can greet the mail server (postal worker):
Note that 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 its existence, as follows:
Now that you have greeted the postal worker and received the correct responses, you can start to fill out the envelope for your letter.
Start by telling the server who the sender is:
If the mail server accepts the sender address, you receive a 250 response:
250 2.1.0 Ok
Now indicate the recipient of the letter:
Again, you should receive a 250 response:
250 2.1.5 Ok
You can add more recipients; unlike a physical letter, the same email can be sent to multiple recipients.
Now you come to the content of the letter: the data.
To start the main body of the message, type:
The response is fairly terse:
354 End data with <CR><LF>.<CR><LF>
Now you enter the subject and the body. You must type the word Subject:
Subject: test message
Press Enter, and then type the body of the message:
This is the body of the message!
As when you used the
As before, you should receive a 250 response:
. 250 2.0.0 Ok: queued as 9620FF0087
You are done with Telnet for the moment, so you can quit:
You are returned to the bash prompt:
221 2.0.0 Bye Connection closed by foreign host. You have new mail in /var/mail/demo
Note that you have new mail in the file where your mail is kept (in this example, /var/mail/demo).
Check the test message
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 demo mail is kept). If you don't see all of the mail as shown in the following example, you can adjust the number of lines to, say, 20. In this example, the output was as follows:
From email@example.com Wed Aug 6 10:33:20 2008 Return-Path: <firstname.lastname@example.org> X-Original-To: email@example.com Delivered-To: firstname.lastname@example.org Received: from test.democloud.com (localhost [127.0.0.1]) by mail.democloud.com (Postfix) with SMTP id 9620FF0087 for <email@example.com>; Wed, 6 Aug 2008 10:28:43 +0000 (UTC) Subject: test message Message-Id: <20080806103059.9620FF0087@mail.democloud.com> Date: Wed, 6 Aug 2008 10:28:43 +0000 (UTC) From: firstname.lastname@example.org To: undisclosed-recipients:; This is the body of the message!
Although it is not practical to go into all the details of what is possible with email headers and messages, encodings and the details of Telnet, this introduction shows how mail works and what steps are taken when mail is sent and received.
You can begin to see why some legitimate mail might be seen as spam email. If any of the steps failed or gave the wrong response, warning flags are raised. A wrong host name means that mail sent from the server does not identify itself properly. Improperly formatted addresses or message bodies can raise flags.
Where to go from here
Now that you have tested that mail is working correctly, you can ensure that the server is not an open relay.
© 2015 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
See license specifics and DISCLAIMER