Professional Documents
Culture Documents
Mail Transfer Agent (MTA)
Mail Transfer Agent (MTA)
Mail Transfer Agent (MTA)
Learn how to configure mail aliases and mail forwarding for the sendmail program on Linux®.
Learn about some alternative mail transfer agents. Use the material in this tutorial to study for
the LPI 102 exam for Linux system administrator certification or to learn for fun.
View more content in this series
Overview
In this tutorial, learn to:
See "Learn Linux, 101: A roadmap for LPIC-1" for a description of and link to each tutorial in
this series. The roadmap is in progress and reflects the version 4.0 objectives of the LPIC-1
exams as updated on April 15th, 2015. As tutorials are completed, they will be added to the
roadmap.
Sendmail is the oldest Linux MTA. It was originally derived from the delivermail program that was
used on the ARPANET in 1979. Today there are several alternative MTAs. In this tutorial, I will also
introduce you to some of these other MTAs.
This tutorial helps you prepare for Objective 108.3 in Topic 108 of the Linux Server Professional
(LPIC-1) exam 102. The objective has a weight of 3.
Prerequisites
To get the most from the tutorials in this series, you need a basic knowledge of Linux and a
working Linux system on which you can practice the commands covered in this tutorial. You should
be familiar with GNU and UNIX commands. Sometimes different versions of a program format
output differently, so your results might not always look exactly like the listings shown here.
In this tutorial, I use Ubuntu 14.04 LTS and sendmail 8.14.4 for the sendmail examples.
Mail transfer
Mail transfer agents such as sendmail deliver mail between users and between systems. Most
Internet mail uses the Simple Mail Transfer Protocol (SMTP), but local mail may be transferred
through files or sockets among other possibilities. Mail is a store and forward operation, so
mail is stored in some kind of file or database until a user collects it or a receiving system or
communication link is available. Configuring and securing an MTA is quite a complex task, most of
which is beyond the scope of this introductory tutorial.
You can use mail interactively to send messages by passing a list of addressees, or with no
arguments you can use it to look at your incoming mail. Listing 1 shows how to send a message
to user steve and user pat on your system with a carbon copy to user bob. When prompted for the
cc:user and the subject, enter the body and complete the message by pressing Ctrl+D (hold down
the Ctrl key and press D).
Ian
If all is well, your mail is sent. If there is an error, you will see an error message. For example, if
you typed an invalid name as a recipient, the mail is not sent. Note that in this example, all users
are on your local system and therefore all must be valid users.
You can also send mail non-interactively using the command line. Listing 2 shows how to send
a small message to users steve and pat. This capability is particularly useful in scripts. Different
versions of the mail command are available in different packages. Some support a -c option for
cc:, but the version I am using here does not, so I specify only the to: addresses.
If you use mail with no options you will see a list of your incoming mail as shown in Listing 3. You
see that user steve has the two messages I sent above, plus an earlier one from me and a later
one from user bob. All the mail is marked as 'N' for new mail.
The currently selected message is shown with a '>', which is message number 1 in Listing 3. If you
press Enter, the first page of the next unread message will be displayed. Press the Space bar
to page through the message. When you finish reading the message and return to the '?' prompt,
press Enter again to view the next message, and so on. At any '?' prompt you can type 'h' to see
the list of message headers again. The ones you have read will now show 'R' in the status as
shown in Listing 4.
Here Steve has read the three messages from Ian but has not read the message from Bob. You
can select individual messages by number, and you can also delete messages that you don't want
by typing 'd', or '3d' to delete the third message. If you type 'q' you will quit the mail command.
Messages that you have read will be transferred to the mbox file in your home directory and the
unread messages will remain in your inbox, by default in /var/mail/$(id -un). See Listing 5.
If you type 'x' to exit instead of 'q' to quit, your mailbox will be left unchanged. Because this is on
the /var file system, your system administrator may allow mail to be kept there only for a limited
time. To reread or otherwise process mail that has been saved to your local mbox file, use the -f
option to specify the file you want to read. For example mail -f mbox.
Mail aliases
In the previous section you saw how mail can be sent to various users on a system. You can use
a fully qualified name, such as ian@myexampledomain.com to send mail to a user on another
system.
Sometimes you might want all the mail for a user to go to some other place. For example, you may
have a server farm and want all the root mail to go to a central system administrator. Or you may
want to create a mailing list where mail goes to several people. To do this, you use aliases that
allow you to define one or more destinations for a given user name. The destinations may be other
user mail boxes, files, pipes, or commands that do further processing. You do this by specifying
the aliases in /etc/mail/aliases or /etc/aliases. Depending on your system, you may find that one of
these is a symbolic link to the other, or you may have only one of them. You need root authority to
change the aliases file.
• A local user name is a text string that matches the name of a user on this system. Technically
this means it can be found using the getpwnam call .
• A local file name is a full path and file name that starts with '/'. It must be writeable by
sendmail. Messages are appended to the file.
• A command starts with the pipe symbol (|). Messages are sent to the command using
standard input.
• An include file alias starts with :include: and specifies a path and file name. The aliases in file
are added to the aliases for this name.
• An external address is an email address such as john@somewhere.com.
You should find an example file, such as /usr/share/sendmail/examples/db/aliases that was
installed with your sendmail package. It contains some recommended aliases for postmaster,
MAILER-DAEMON, abuse, and spam. In Listing 6, I have combined entries from the example file
on my Ubuntu 14.04 LTS system with some rather artificial examples that illustrate several of the
possibilities.
#
# Mail aliases for sendmail
#
# You must run newaliases(1) after making changes to this file.
#
# Required aliases
postmaster: root
MAILER-DAEMON: postmaster
# Common aliases
abuse: postmaster
spam: postmaster
# Other aliases
# Send pat's mail to a file in her home directory and also to her inbox.
# Finally send it to a command that will make another copy.
pat: /home/pat/accumulated-mail,
\pat,
|/home/pat/makemailcopy.sh
Note that pat is both an alias and a user of the system. Alias expansion is recursive, so if an alias
is also a name, then it will be expanded. Sendmail does not send mail twice to a given user, so if
you just put 'pat' as an alias for 'pat', then it would be ignored since sendmail had already found
and processed 'pat'. To avoid this problem, you prefix an alias name with a '\' to indicate that it is a
name not subject to further aliasing. This way, pat's mail can be sent to her normal inbox as well as
the file and command.
Lines in the aliases that start with '$' are comments and are ignored. Lines that start with blanks
are treated as continuation lines.
Listing 10 shows the files that are updated when you put all this to the test.
• There is a user 'mail' with group name 'mail' that is used by sendmail.
• User mail is stored by sendmail in /var/mail which is also the home directory of user 'mail'.
The inbox for user 'ian' defaults to /var/mail/ian.
• If you want sendmail to write files in a user directory, the file must be writeable by sendmail.
Rather than making it world writeable, it is customary to make it group writeable and make the
group 'mail'. You may need a system administrator to do this for you.
Postfix started life at IBM research as an alternative to sendmail. It attempts to be fast, easy to
administer, and secure. The outside looks somewhat like sendmail, but the inside is completely
different.
Qmail is a secure, reliable, efficient, simple message transfer agent developerd by Dan Bernstein.
However, the core qmail package has not been updated for many years. Qmail and several other
packages have now been collected into IndiMail.
Exim is another MTA developed at the University of Cambridge. Originally, the name stood for
EXperimental Internet Mailer.
All of these MTAs were designed as sendmail replacements, so they all have some form of
sendmail compatibility. Each can handle aliases and .forward files. Some provide a sendmail
command as a front end to the particular MTA's own command. Most allow the usual sendmail
options, although some options might be ignore silently. The mailq command is supported directly
or by an alternate command with a similar function. For example, you can use mailq or exim -bp to
display the exim mail queue. Needless to say, output can look different compared to that produced
by sendmail's mailq command.
See Related topics where you can find more information on all of these MTAs.
Related topics
• Use the developerWorks roadmap for LPIC-1 to find the developerWorks tutorials to help you
study for LPIC-1 certification based on the LPI Version 4.0 April 2015 objectives.
• At the Linux Professional Institute website, find detailed objectives, task lists, and sample
questions for the certifications. In particular, see:
• The LPIC-1: Linux Server Professional Certification program details
• LPIC-1 exam 101 objectives
• LPIC-1 exam 102 objectives
Always refer to the Linux Professional Institute website for the latest objectives.
• Learn more about SENDMAIL An Internetwork Mail Router.
• Find sendmail documentation at sendmail.org, including the SENDMAIL Installation and
Operation Guide.
• Find MTA home pages at Postfix, Exim, and Qmail.
• The Simple Mail Transfer Protocol (SMTP) is described in IETF RFC 5321.