12.2. sendmail Configuration Files
sendmail
reads a configuration file (typically called
/etc/mail/sendmail.cf, or in older
distributions, /etc/sendmail.cf, or even
/usr/lib/sendmail.cf ) that is simple for
sendmail to parse, but not simple for a system administrator to read
or edit. Fortunately, most sendmail configuration does not involve
reading or editing the sendmail.cf file. Most
sendmail configuration is macro driven. The macro method generates
configurations to cover most installations, but you always have the
option of tuning the resultant sendmail.cf
manually.The m4 macro processor program processes a
macro configuration file to generate the
sendmail.cf file. For our convenience, we refer
to the macro configuration file as the
sendmail.mc file throughout this chapter. Do not
name your configuration file sendmail.mc.
Instead, give it a descriptive name. For example, you might name it
after the host it was designed
forvstout.m4, in our case. Providing a
unique name for the configuration file allows you to keep all
configuration files in the same directory and is an administrative
convenience. The configuration process is basically a
matter of creating a sendmail.mc file that
includes the macros that describe your desired configuration, and
then processing that sendmail.mc file with m4.
The sendmail.mc file may include basic m4
commands such as define or
divert, but the lines in the file that have the
most dramatic effect on the output file are the sendmail macros. The
sendmail developers define the macros used in the
sendmail.mc file. The m4 macro processor expands
the macros into chunks of sendmail.cf syntax.
The macro expressions included in the
sendmail.mc file begin with the macro name
(written in capital letters), followed by parameters (enclosed in
brackets) that are used in the macro expansion. The parameters may be
passed literally into the sendmail.cf output or
may be used to govern the way the macro processing occurs.Unlike a sendmail.cf file, which may be more
than 1,000 lines long, a basic sendmail.mc file
is often less than 10 lines long, excluding comments.
12.2.1. Comments
Lines in the
sendmail.mc file that begin with the
# character are not parsed by m4, and, by default,
are output directly into the sendmail.cf file.
This is useful if you want to comment on what your configuration is
doing in both the sendmail.mc and the
sendmail.cf files.
To put
comments in the sendmail.mc that are
not placed into the
sendmail.cf, use either m4
divert or dnl commands.
divert(-1) causes all output to cease.
divert(0) restores output to the default. Any
lines between these will be discarded. Blocks of comments that should
appear only in the sendmail.mc file are
usually brackets by divert(-1) and
divert(0) commands. To achieve the same result for
a single line, use the dnl command at the
beginning of a line that should appear as a comment only in the
sendmail.mc file. The dnl
command means "delete all characters up to and
including the next newline." Sometimes
dnl is added to the end of a macro command line,
so that anything else added to that line is treated as a comment.Often there are more comments than configuration commands in a
sendmail.mc file! The following sections explain
the structure of the sendmail.mc file and the
commands used in the file.
12.2.2. Typically Used sendmail.mc Commands
A
few commands are used to build most sendmail.mc
files. Some of these typically used commands and the general sequence
of these commands in the sendmail.mc are as
follows:VERSIONIDOSTYPEDOMAINFEATUREdefineMAILERLOCAL_*
The commands in this list that are written
in uppercase are sendmail macros. By convention, the sendmail
developers use uppercase letters for the names of the macros they
create. There are more macros than those shown above. See the file
cf/README for a complete list of the sendmail
macros. In the list above, everything except the
define command is a sendmail macro. The
define command, which is shown in lowercase, is a
basic m4 command. All basic m4 commands are written in lowercase
letters. There are other basic m4 commands used in
sendmail.mc files; in fact you can use any legal
m4 command in a sendmail.mc file. However, the
commands listed above are the basic set used to show the general
order in which commands occur in a sendmail.mc
file. We examine each of these commands in the following sections.
12.2.2.1 VERSIONID
The
VERSIONID macro defines version control
information. This macro is optional, but is found in most of the
sendmail m4 files. The command has no required format for the
arguments field. Use any version control information you desire.
Generally this is something compatible with the revision control
system you use. If you don't use a revision control
system, put a descriptive comment in this field. The
VERSIONID macro from a
sendmail.mc file on a system that did not use
version control might look something like the following:
VERSIONID(`sendmail.mc, 6/11/2004 18:31 by Win Henson')Notice
that the argument is enclosed in single quotes and that the opening
quote is ` and the closing quotes is '. When the
argument passed to the sendmail macro contains spaces, special
characters or values that may be misinterpreted as m4 commands, the
argument is enclosed in quotes, and it must be enclosed using these
specific single quotes. This is true for all macros, not just
VERSIONID.
12.2.2.2 OSTYPE
The
OSTYPE macro is a required part of the macro
configuration file. The OSTYPE macro command loads
an m4 source file that defines operating system-specific information,
such as file and directory paths, mailer pathnames, and
system-specific mailer arguments. The only argument passed to the
OSTYPE command is the name of the m4 source file
that contains the operating system-specific information.
OSTYPE files are stored in the
cf/ostype directory. The command
OSTYPE(`linux')
processes the cf/ostype/linux.m4 file.The sendmail distribution provides more than 40 predefined operating
system macro files in the cf/ostype directory,
and you can create your own for a specific Linux distribution if you
like. Some Linux distributions, notably the Debian distribution,
include their own definition file that is completely Linux-FHS
compliant. When your distribution does this, use its definition
instead of the generic-linux.m4 file. The
OSTYPE macro should be one of the first commands
to appear in the sendmail.mc file, as many other
definitions depend on it.
12.2.2.3 DOMAIN
The DOMAIN macro
processes the specified file from the cf/domain
directory. A DOMAIN file is useful when
configuring a large number of machines on the same network in a
standard way, and typically configures items such as the name of mail
relay hosts or hubs that all hosts on your network use.To
make effective use of the DOMAIN macro, you must
create your own macro file containing the standard definitions you
require for your site, and write it into the
domain subdirectory. If you saved your domain
macro file as cf/domain/vbrew.m4,
you'd invoke it in your
sendmail.mc using:
DOMAIN(`vbrew')The sendmail distribution comes with a number of sample domain macro
files that you can use to model your own. One is the
domain/generic.m4 file shown later in Example 12-3.
12.2.2.4 FEATURE
Use
the FEATURE macro to include predefined sendmail
features in your configuration. There are a large number of
featuresthe cf/feature directory contains
about 50 feature files. In this chapter we'll talk
about only a few of the more commonly used features. You can find
full details of all of the features in the
cf/README file included in the source package.To use a feature, include a line in
the sendmail.mc that looks like:
FEATURE(name)where name is the feature name. Some
features take an optional parameter in a format like:
FEATURE(name, param)where param is the parameter to supply.
12.2.2.5 define
Use the m4 define
command to set values for internal sendmail.cf
macros, options, or classes. The first argument passed to the
define is the m4 name of the variable being set
and the second field is the value to which the variable is set. Here
is an example of how define is used to set a
sendmail.cf macro:
define(`confDOMAIN_NAME', `vstout.vbrew.com')The define command shown above places the
following in the sendmail.cf file.
Djvstout.vbrew.comThis sets the sendmail.cf macro
$j, which holds the full domain name of the
sendmail host, to vstout.vbrew.com.
Manually setting a value for $j is generally not
necessary because, by default, sendmail obtains the correct name for
the local host from the system itself.Most of the m4 variables default to
a reasonable value and thus do not have to be explicitly set in the
m4 source file. The undefine command sets a
variable back to its default. For example:
undefine(`confDOMAIN_NAME')Resets confDOMAIN_NAME to the default value even
if the configuration had previously set it to a specific hostname.The list of m4
variables that can be set by define is quite long.
The cf/README file lists all of the variables.
The listing includes the m4 variable name, the name of the
corresponding sendmail.cf option, macro, or
class, a description of the variable, and the default value that is
used if you do not explicitly define a value for the variable.Note that the define command is not limited to setting values for
sendmail.cf macros, options, and classes.
define is also used to modify values used in the
m4 configurations and internal sendmail values.
12.2.2.6 MAILER
If you
want sendmail to transport mail in any way other than by local
delivery, use the MAILER macro to tell it which
transports to use. sendmail supports a variety of mail transport
protocols; some are essential, some are rarely used, and a few are
experimental. The mailer arguments that can be used with the
MAILER macro are shown in Table 12-2.
among other hosts, and the local mailer to move
mail among users on the system. To achieve this, include both
MAILER(`local')
and
MAILER(`smtp')
in the macro configuration file. (The local mail
transport is included by default, but is usually specified in the
macro configuration file for clarity.)The
MAILER(`local')
macro adds the local mailer, which delivers local
mail between users of the system, and the prog
mailer, which sends mail files to programs running on the system. The
MAILER(`smtp')
macro includes all of the mailers needed to send SMTP mail over a
network. The mailers included in the sendmail.cf
file by the
MAILER(`smtp')
macro are:smtp
This mailer handles only traditional 7-bit ASCII SMTP mail.
esmtp
This mailer supports Extended SMTP (ESMTP), which understands the
ESMTP protocol extensions and the complex message bodies and enhanced
data types of MIME mail. This is the default mailer used for SMTP
mail.
smtp8
This mailer sends 8-bit data to the remote server, even if the remote
server does not support ESMTP.
dsmtp
This
mailer supports the ESMTP ETRN command that allows the destination
system to retrieve mail queued on the server.
relay
This mailer is used to relay SMTP mail through another mail server.
Every system that connects to or communicates with the Internet needs
the
MAILER(`smtp')
set of mailers, and most systems on isolated networks use these
mailers because they use TCP/IP on their enterprise network. Despite
the fact that the vast majority of sendmail systems require these
mailers, installing them is not the default. To support SMTP mail,
you must add the MAILER(smtp) macro to your
configuration.
12.2.2.7 LOCAL_*
The LOCAL_CONFIG,
LOCAL_NET_CONFIG,
LOCAL_RULESET, and
LOCAL_RULE_n macros
allow you to put sendmail.cf configuration
commands directly in the m4 source file. These commands are copied,
exactly as written, into the correct part of the
sendmail.cf file. The list below describes where
the macros place the sendmail.cf configuration
commands that you provide.LOCAL_CONFIG
Marks the start of a block of sendmail.cf
commands to be added to the local information section of the
sendmail.cf file.
LOCAL_NET_CONFIG
Marks the start of a section of rewrite rules that are to be added to
the end of ruleset 0, which is also called ruleset
parse.
LOCAL_RULE_ n
Marks the start of a section of rewrite rules to be added to ruleset
0, 1, 2, or 3. The n identifies the
ruleset to which the rewrite rules are to be added.
LOCAL_RULESET
Marks the start of a custom ruleset to be added to the configuration.
These macro mean that everything that can be done in the
sendmail.cf file can be done in the m4 macro
configuration file because not only do you have access to all of the
m4 macros, you have access to all of the
sendmail.cf commands. Of course, before you can
use the sendmail.cf commands you need some idea
of how they work. The next section briefly covers the
sendmail.cf configuration commands.