Book: LPI Linux Certification in a Nutshell
Section: Chapter 20.  Networking Services (Topic 1.13)



20.2 Objective 2: Operate and Perform Basic Configuration of sendmail

The sendmail Mail Transfer Agent (or MTA) is responsible for handling a large portion of email sent on the Internet and inside enterprises. It has broad capabilities to handle mail routing and can perform complex rewriting of email addresses. It also has a long history of deployment on early networked systems where I/O bottlenecks were significant. As a result of this history, sendmail's configuration file was constructed over the years to be succinct and small, allowing it to be read quickly by the sendmail daemon. Unfortunately, it can also appear to be somewhat cryptic to administrators, and detailed configuration of sendmail has become known as somewhat of an art.

Configuration details of sendmail are nontrivial and beyond the scope of the LPIC Level 1 exams. However, a basic sendmail configuration for a system in an established domain is relatively simple to implement and is covered in Exam 102.

20.2.1 Configuring sendmail

The sendmail configuration file is /etc/sendmail.cf. This text file contains information to control the processing of mail on your system, and it is read at every invocation of sendmail. Each line in the file defines a configuration command, which begins with a short one- or two-letter command definition. The file can also contain comments beginning with #. To simplify a basic setup, example sendmail.cf files exist in most installations.

20.2.1.1 The smart host parameter

To enable mail transfer inside an established organization, you need to configure sendmail to transfer messages to a smart host, most likely the main mail-processing system in your domain. For example, if your enterprise's mail is handled by mail.yourdomain.com, you can configure your Linux systems to transfer all mail to that computer for further processing. To make this change, simply use the DS directive in sendmail.cf :

DSmail.yourdomain.com

20.2.2 Mail Aliases

Even on simple sendmail installations, it's useful to configure some of your system users to have their mail redirected to another user. For example, artificial users such as nobody shouldn't receive mail, so forwarding any mail received for that username to an administrator may help with problem solving. This forwarding is accomplished using mail aliases. A mail alias is simply a mapping from a username to one or more recipients in this form:

sysadmin:       jdean, bsmith

Aliases are defined in /etc/aliases. Local mail intended for sysadmin is received by both jdean and bsmith on the local system, as shown in Example 20-2.

Example 20-2. A Typical /etc/aliases File
# Basic system aliases -- these MUST be present.
MAILER-DAEMON:  postmaster
postmaster:     root

# General redirections for pseudo accounts.
bin:            root
daemon:         root
games:          root
ingres:         root
nobody:         root
system:         root
toor:           root
uucp:           root

# Well-known aliases.
manager:        root
dumper:         root
operator:       root
webmaster:      root
abuse:          root
spam:           root

# Trap decode to catch security attacks
decode:         root

# Person who should get root's mail
root:           jdean

# Departmental accounts
sales:          bsmith
support:        jdoe

sendmaildoesn't actually read the text aliases file, since it's not uncommon to find many aliases defined there. Instead, it reads a compiled database, /etc/aliases.db, built from /etc/aliases. Therefore, the database must be updated after any change is made to aliases, using the newaliases command; newaliases has no options and must be run as root.

20.2.2.1 Forwarding mail from your account to another account

In addition to permanently established mail aliases, individual users have the capability to create their own mail aliases on an as-needed basis by using a .forward file in the home directory. Mail is sent to the alias by simply putting an email address on a line by itself in .forward.

On the Exam

Remember, the /etc/aliases and .forward files define mail aliases, and the newaliases command must be executed after changing the aliases file to recreate the alias database.

20.2.3 Queued Mail

If sendmail cannot deliver mail immediately, such as on a system using an intermittent dialup connection, mail is queued for later processing. To see the mail queue, use the mailq command, like this:

$ mailq
Mail Queue (2 requests)
--Q-ID-- --Size-- -Priority- ---Q-Time--- -Sender/Recipient
WAA12372     3427      30043 Jul  4  2:19 bsmith
                 (host map: lookup (mydom.com): deferred)
                                          [email protected]
WAA12384      313      30055 Jul  8 22:40 jdoe
                 (host map: lookup (yourdom.com): deferred)
                                          [email protected]

The first line printed for each message shows the internal identifier used on the local host for the message, the size of the message in bytes, the date and time the message was accepted into the queue, and the sender of the message. The second line shows the error message that caused this mail to be retained in the queue. Subsequent lines show message recipients. In this example, two outbound messages are queued because the DNS host lookups did not succeed.

On the Exam

Be aware that mail could be queued by sendmail and that mailq displays a list of those messages.

20.2.4 Starting and Stopping sendmail

sendmail is typically managed through the runlevel system and the series of scripts and links in /etc/rc.d. See Section 20.3 for details on starting and stopping services.