MTA - mail transfer Agents

Configuring Email on Linux Systems

What is a MTA?

A MTA (Mail Transfer Agent) is the software that is installed on your Linux server for the handling of email. There are many types of MTAs available for Linux. The four main MTAs that are in common use are Postfix, Sendmail, Qmail and Exim.


Sendmail is a popular choice for a MTA. Many Linux and Unix systems have shipped with Sendmail as a default MTA. Today probably Postfix is more common due to its enhanced security. Sendmail is normally available in most Linux repositories.


Exim was originally developed to fix some of the security issues that were found with Sendmail. Exim was originally created at Cambridge University back in 1995. Exim is still a very popular MTA as it is often used as a direct replacement for Sendmail.


Qmail is a MTA that was developed during the mid 1990s. Qmail was developed to be a more secure MTA than the popular Sendmail MTA. The main Qmail package was placed into the Public Domain for further development during late 2007. Many third party companies and individuals provide various levels of support and patches for this product. Qmail can still be found on many older servers today.


Postfix was originally developed by Wietse Venema. Postfix was created to enhance the functionality that was found in Sendmail. The main enhancements were related to security features. Postfix is probably one of the easiest of MTAs to configure. Postfix is the default MTA that is shipped with many Linux distributions.

Postfix Basic Configuration and Installation

In the following example, we will look at configuring postfix on a SLES 11sp2 server. By default postfix was installed on our SLES server. We can verify this by using the zypper package management tool:

sles01:/etc/postfix # zypper se postfix
Loading repository data...
Reading installed packages...

S | Name          | Summary                                | Type
i | postfix       | A fast, secure, and flexible mailer    | package
  | postfix       | A fast, secure, and flexible mailer    | srcpackage
  | postfix-doc   | Documentations for the postfix package | package
  | postfix-mysql | Postfix plugin to support MySQL maps   | package

In the above example, the "i" in the first column signifies that "postfix" is already installed. If your distribution does not show "postfix" as being already installed, you can simply install postfix by issuing the command zypper in postfix

Alternatively, If you are using a Debian based system you can issue the sudo apt-get install postfix command.

Assuming now that we have postfix installed, we can try a quick connectivity test using the "telnet" tool:

Test connection

sles01:/etc/postfix # telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 sles01.tst.domain ESMTP Postfix
221 2.0.0 Bye
Connection closed by foreign host.

If all has gone well, you should see some output similar to that of the above.

Postfix configuration file

Postfix has one main configuration file which can be found in the following location: "/etc/postfix/"

The configuration file may look quite daunting at first view, however, most of this file is actually commented out with "#" hashes. Each section is explained in detail. Below are the settings I have used on my test system. In this example, I am going to forward all email to a dedicated email server using the relayhost option. You will need to modify the configuration file to match your domain names.

Basic settings

mydestination = $myhostname, localhost.$mydomain

relayhost =

myhostname = hostname of your server.

The above are the only changes I needed to make to our configuration file.


The mydomain parameter specifies the local internet domain name. The default is to use $myhostname minus the first component. $mydomain is used as a default value for many other configuration parameters.


The mydestination parameter specifies the list of domains that this machine considers itself the final destination for.


The relayhost parameter specifies the default host to send mail to. In my configuration, I use this entry to pass all emails to a dedicated email server. Amend this entry to match your network.


The myhostname parameter specifies the internet hostname of this mail system. The default is to use the fully-qualified domain name from gethostname(). $myhostname is used as a default value for many other configuration parameters.

Test Email

We can test our email server by issuing the following command to send an email:

john@sles01:~> mail -s "I am the subject line" john@tst.domain
I am the body of my email

The "." dot is important as this signifies that this is the end of the email.

sles01:/var/spool/mail # pwd
sles01:/var/spool/mail # ls -rtl
total 2712
-rw------- 1 test   users      605 Mar 27 10:08 test
-rw------- 1 nagios nagios 2758177 Apr 30 13:41 nagios
-rw------- 1 root   root      1646 May  7 11:55 root
-rw------- 1 test01 users      597 May 21 11:37 test01

To view any emails that have been sent from your system, you can interrogate the following log file:

/var/log/mail contains emails that have been sent...

May 21 11:37:23 sles01 postfix/pickup[31076]: 6F9C013637: uid=1008 from=
May 21 11:37:23 sles01 postfix/cleanup[31877]: 6F9C013637: message-id=<20130521103723.6F9C013637@sles01.tst.domain>
May 21 11:37:23 sles01 postfix/qmgr[31077]: 6F9C013637: from=<john@sles01.tst.domain>, size=457, nrcpt=1 (queue active)
May 21 11:37:23 sles01 postfix/local[31879]: 6F9C013637: to=<test01@sles01.tst.domain>, orig_to=, relay=local, delay=0.05, delays=0.03/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
May 21 11:37:23 sles01 postfix/qmgr[31077]: 6F9C013637: removed

Email Aliases

Aliases take the format of "alias: user" account. After you make any modifications to this file, you must run the command newaliases as root. Alias entries can be created in the following location: /etc/aliases

nagiosadmin:    root
john:           test01

In the above, emails are sent from the nagiosadmin account to the root users email account and emails for john also go to the account test01. If we change the above alias list and replace the test01 account with john, then the account test01 will no longer receive emails for john. For clarity, I have left the entry for john, however, in practice, if an alias was not needed, you would completely remove the entry.

nagiosadmin:    root
john:           john

After making a change to the alias file, you must run the "newaliases" command to refresh the postfix database.

Now when we run the email command again, we can see the changes referenced in the log file below.

john@sles01:~> mail -s "This is a new test" john
A new test email.

Now if we compare the results to the previous example found in the "/var/log/mail" file:

May 21 11:49:41 sles01 postfix/pickup[31076]: CF9432B83E: uid=1008 from=
May 21 11:49:41 sles01 postfix/cleanup[32130]: CF9432B83E: message-id=<20130521104941.CF9432B83E@sles01.tst.domain>
May 21 11:49:41 sles01 postfix/qmgr[31077]: CF9432B83E: from=<john@sles01.tst.domain>, size=475, nrcpt=1 (queue active)
May 21 11:49:41 sles01 postfix/local[32132]: CF9432B83E: to=<john@sles01.tst.domain>, orig_to=, relay=local, delay=0.11, delays=0.07/0.02/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox)
May 21 11:49:41 sles01 postfix/qmgr[31077]: CF9432B83E: removed

This time the email was sent to the recipient john and not test01.

Accessing Email

To access emails locally on your server you can issue the command "mail":

john@sles01:~> mail
Heirloom mailx version 12.2 01/07/07.  Type ? for help.
"/var/spool/mail/john": 2 messages 2 new
>N  1 Tue May 21 11:47   18/610   My email
 N  2 Tue May 21 11:49   18/615   This is a new test
? 2
Message  2:
From john@sles01.tst.domain  Tue May 21 11:49:41 2013
X-Original-To: john
Delivered-To: john@sles01.tst.domain
Date: Tue, 21 May 2013 11:49:41 +0100
To: john@sles01.tst.domain
Subject: This is a new test
User-Agent: Heirloom mailx 12.2 01/07/07
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: john@sles01.tst.domain (John Reed)

A new test email.

Postfix Help

For further help with postfix, don't forget you can always consult the man pages or visit the official postfix web site:

Postfix Web Site

Here you will find full documentation and and howto guides covering everything you could possibly want to know regarding postfix.