old-www/LDP/nag2/x14661.html

1012 lines
19 KiB
HTML

<HTML
><HEAD
><TITLE
>The sendmail.cf and sendmail.mc Files</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.57"><LINK
REL="HOME"
TITLE="Linux Network Administrators Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="Sendmail"
HREF="x-087-2-sendmail.html"><LINK
REL="PREVIOUS"
TITLE="Overview of Configuration Files"
HREF="x14644.html"><LINK
REL="NEXT"
TITLE="Generating the sendmail.cf File"
HREF="x14903.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Linux Network Administrators Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x14644.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 18. Sendmail</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x14903.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN14661"
>18.4. The sendmail.cf and sendmail.mc Files</A
></H1
><P
>&#13;
The <B
CLASS="COMMAND"
>m4</B
> macro processor program generates the
<TT
CLASS="FILENAME"
>sendmail.df</TT
> file when it processes the macro
configuration file provided by the local system administrator. Throughout the
remainder of this chapter we will refer to this configuration file as the
<TT
CLASS="FILENAME"
>sendmail.mc</TT
> file.</P
><P
>The configuration process is basically a matter of creating a suitable
<TT
CLASS="FILENAME"
>sendmail.mc</TT
> file that includes macros that describe
your desired configuration. The macros are expressions that the
<B
CLASS="COMMAND"
>m4</B
> macro processor understands and expands into
the complex <TT
CLASS="FILENAME"
>sendmail.cf</TT
> syntax. The macro expressions
are made up of the macro name (the text in capital letters at the start),
which can be likened to a function in a programming language, and some
parameters (the text within brackets) that are used in the expansion. The
parameters may be passed literally into the <TT
CLASS="FILENAME"
>sendmail.cf</TT
>
output or may be used to govern the way the macro processing occurs.</P
><P
>A <TT
CLASS="FILENAME"
>sendmail.mc</TT
> file for a minimal configuration (UUCP or
SMTP with all nonlocal mail being relayed to a directly connected
smart host) can be as short as 10 or 15 lines, excluding comments.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN14682"
>18.4.1. Two Example sendmail.mc Files</A
></H2
><P
>&#13;If you're an administator of a number of different mail hosts, you might not
want to name your configuration file <TT
CLASS="FILENAME"
>sendmail.mc</TT
>.
Instead, it is common practice to name it after the
host&#8212;<TT
CLASS="FILENAME"
>vstout.m4</TT
> in our case. The name doesn't
really matter as long as the output is called
<TT
CLASS="FILENAME"
>sendmail.cf</TT
>. Providing a unique name for the
configuration file for each host allows you to keep all configuration files
in the same directory and is just an administrative convenience. Let's look
at two example macro configuration files so we know where we are
heading.</P
><P
>&#13;Most <B
CLASS="COMMAND"
>sendmail</B
> configurations today use SMTP only. It is
very simple to configure <B
CLASS="COMMAND"
>sendmail</B
> for SMTP.
<A
HREF="x14661.html#X-087-2-SENDMAIL.MC.SMTP"
>Example 18-1</A
> expects a DNS name server to be
available to resolve hosts and will attempt to accept and deliver all mail
for hosts using just SMTP.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="X-087-2-SENDMAIL.MC.SMTP"
></A
><P
><B
>Example 18-1. Sample Configuration File vstout.smtp.m4</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>divert(-1)
#
# Sample configuration file for vstout - smtp only
#
divert(0)
VERSIONID(`@(#)sendmail.mc 8.7 (Linux) 3/5/96')
OSTYPE(`linux')
#
# Include support for the local and smtp mail transport protocols.
MAILER(`local')
MAILER(`smtp')
#
FEATURE(rbl)
FEATURE(access_db)
# end</PRE
></TD
></TR
></TABLE
></DIV
><P
>A <TT
CLASS="FILENAME"
>sendmail.mc</TT
> file for
<SPAN
CLASS="SYSTEMITEM"
>vstout</SPAN
> at the Virtual Brewery is shown
in <A
HREF="x14661.html#X-087-2-SENDMAIL.MC.UUCPSMTP"
>Example 18-2</A
>.
<SPAN
CLASS="SYSTEMITEM"
>vstout</SPAN
> uses SMTP to talk to all hosts
on the Brewery's LAN, and you'll see the commonality with the generic SMTP-only
configuration just presented. In addition, the
<SPAN
CLASS="SYSTEMITEM"
>vstout</SPAN
> configuration sends all mail
for other destinations to <SPAN
CLASS="SYSTEMITEM"
>moria</SPAN
>,
its Internet relay host, via UUCP.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="X-087-2-SENDMAIL.MC.UUCPSMTP"
></A
><P
><B
>Example 18-2. Sample Configuration File vstout.uucpsmtp.m4</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>divert(-1)
#
# Sample configuration file for vstout
#
divert(0)
VERSIONID(`@(#)sendmail.mc 8.7 (Linux) 3/5/96')
OSTYPE(`linux')
dnl
# moria is our smart host, using the "uucp-new" transport.
define(`SMART_HOST', `uucp-new:moria')
dnl
# Support the local, smtp and uucp mail transport protocols.
MAILER(`local')
MAILER(`smtp')
MAILER(`uucp')
LOCAL_NET_CONFIG
# This rule ensures that all local mail is delivered using the
# smtp transport, everything else will go via the smart host.
R$* &#60; @ $* .$m. &#62; $* $#smtp $@ $2.$m. $: $1 &#60; @ $2.$m. &#62; $3
dnl
#
FEATURE(rbl)
FEATURE(access_db)
# end</PRE
></TD
></TR
></TABLE
></DIV
><P
>If you compare and contrast the two configurations, you might be able to
work out what each of the configuration parameters does. We'll explain them
all in detail.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN14713"
>18.4.2. Typically Used sendmail.mc Parameters</A
></H2
><P
>&#13;
A few of the items in the <TT
CLASS="FILENAME"
>sendmail.mc</TT
> file are required
all the time; others can be ignored if you can get away with defaults.
The general sequence of the definitions in the <TT
CLASS="FILENAME"
>sendmail.mc</TT
>
is as follows:
<P
></P
><OL
TYPE="1"
><LI
><P
><SPAN
CLASS="SYSTEMITEM"
>VERSIONID</SPAN
></P
></LI
><LI
><P
><SPAN
CLASS="SYSTEMITEM"
>OSTYPE</SPAN
></P
></LI
><LI
><P
><SPAN
CLASS="SYSTEMITEM"
>DOMAIN</SPAN
></P
></LI
><LI
><P
><SPAN
CLASS="SYSTEMITEM"
>FEATURE</SPAN
></P
></LI
><LI
><P
>Local macro definitions</P
></LI
><LI
><P
><SPAN
CLASS="SYSTEMITEM"
>MAILER</SPAN
></P
></LI
><LI
><P
><SPAN
CLASS="SYSTEMITEM"
>LOCAL_*</SPAN
> rulesets</P
></LI
></OL
>
We'll talk about each of these in turn in the following sections and refer
to our examples in <A
HREF="x14661.html#X-087-2-SENDMAIL.MC.SMTP"
>Example 18-1</A
> and
<A
HREF="x14661.html#X-087-2-SENDMAIL.MC.UUCPSMTP"
>Example 18-2</A
>, when appropriate, to explain them.</P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14746"
>18.4.2.1. Comments</A
></H3
><P
>Lines in the <TT
CLASS="FILENAME"
>sendmail.mc</TT
> file that begin with the
<TT
CLASS="LITERAL"
>#</TT
> character are not parsed by <B
CLASS="COMMAND"
>m4</B
>, and
will by default be output directly into the
<TT
CLASS="FILENAME"
>sendmail.cf</TT
> file. This is useful if you want to comment
on what your configuration is doing in both the input and output files.</P
><P
>To allow comments in your <TT
CLASS="FILENAME"
>sendmail.mc</TT
> that are
<I
CLASS="EMPHASIS"
>not</I
> placed into the
<TT
CLASS="FILENAME"
>sendmail.cf</TT
>, you can use the <B
CLASS="COMMAND"
>m4</B
>
<SPAN
CLASS="SYSTEMITEM"
>divert</SPAN
> and
<SPAN
CLASS="SYSTEMITEM"
>dnl</SPAN
> tokens.
<SPAN
CLASS="SYSTEMITEM"
>divert(-1)</SPAN
> will cause all output to
cease. <SPAN
CLASS="SYSTEMITEM"
>divert(0)</SPAN
> will cause output to
be restored to the default. Any output generated by lines between
these will be discarded. In our example, we've used this mechanism to
provide a comment that appears only in the <TT
CLASS="FILENAME"
>sendmail.mc</TT
>
file. To achieve the same result for a single line, you can use the
<SPAN
CLASS="SYSTEMITEM"
>dnl</SPAN
> token that means, literally,
&#8220;starting at the beginning of the next line, delete all characters up
to and including the next newline.&#8221; We've used this in
our example, too.</P
><P
>These are standard <B
CLASS="COMMAND"
>m4</B
> features, and you can obtain more
information on them from its manual page.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14766"
>18.4.2.2. VERSIONID and OSTYPE</A
></H3
><P
>&#13;<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>VERSIONID(`@(#)sendmail.mc 8.9 (Linux) 01/10/98')</PRE
></TD
></TR
></TABLE
>
The <TT
CLASS="LITERAL"
>VERSIONID</TT
> macro is optional, but is useful to record
the version of the sendmail configuration in the
<TT
CLASS="FILENAME"
>sendmail.cf</TT
> file. So you'll often encounter it, and we
recommend it. In any case, be sure to include:</P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>OSTYPE(`linux')</PRE
></TD
></TR
></TABLE
>
This is probably the most important definition. The
<TT
CLASS="LITERAL"
>OSTYPE</TT
> macro causes a file of definitions to be
included that are good defaults for your operating system. Most of the
definitions in an <TT
CLASS="LITERAL"
>OSTYPE</TT
> macro file set the
pathnames of various configuration files, mailer program paths and
arguments, and the location of directories sendmail uses to store
messages. The standard sendmail source code release includes such
a file for Linux, which would be included by the previous
example. Some Linux distributions, notably the Debian distribution,
include their own definition file that is completely Linux-FHS
compliant. When your distribution does this, you should probably use
its definition instead of the Linux default one.</P
><P
>The <SPAN
CLASS="SYSTEMITEM"
>OSTYPE</SPAN
> definition should
be one of the first definitions to appear in your
<TT
CLASS="FILENAME"
>sendmail.mc</TT
> file, as many other definitions
depend upon it.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14783"
>18.4.2.3. DOMAIN</A
></H3
><P
>&#13;The <SPAN
CLASS="SYSTEMITEM"
>DOMAIN</SPAN
> macro is useful
when you wish to configure a large number of machines on the same
network in a standard way. It you're configuring a small number of
hosts, it probably isn't worth bothering with. You typically configure
items, such as the name of mail relay hosts or hubs that all hosts on
your network will use.</P
><P
>The standard installation contains a directory of <B
CLASS="COMMAND"
>m4</B
> macro
templates used to drive the configuration process. This directory is usually
named <TT
CLASS="FILENAME"
>/usr/share/sendmail.cf</TT
> or something similar. Here
you will find a subdirectory called <TT
CLASS="FILENAME"
>domain</TT
> that
contains domain-specific configuration templates. To make use of the
<SPAN
CLASS="SYSTEMITEM"
>DOMAIN</SPAN
> macro, you must create your
own macro file containing the standard definitions you require for your site,
and write it into the <TT
CLASS="FILENAME"
>domain</TT
> subdirectory. You'd
normally include only the macro definitions that were unique to your domain
here, such as smart host definitions or relay hosts, but you are not limited
to these.</P
><P
>The <B
CLASS="COMMAND"
>sendmail</B
> source distribution comes with a number of
sample domain macro files that you can use to model your own.</P
><P
>If you saved your domain macro file as
<TT
CLASS="FILENAME"
>/usr/share/sendmail.cf/domain/vbrew.m4</TT
>, you'd
include definitions in your <TT
CLASS="FILENAME"
>sendmail.mc</TT
> using:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>DOMAIN(`vbrew')</PRE
></TD
></TR
></TABLE
></P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14801"
>18.4.2.4. FEATURE</A
></H3
><P
>&#13;The <SPAN
CLASS="SYSTEMITEM"
>FEATURE</SPAN
> macro enables you to
include predefined <B
CLASS="COMMAND"
>sendmail</B
> features in your configuration.
These <B
CLASS="COMMAND"
>sendmail</B
> features make the supported configurations
very simple to use. There are a large number, and throughout this
chapter we'll talk about only a few of the more useful and important ones.
You can find full details of the features available in the
<TT
CLASS="FILENAME"
>CF</TT
> file included in the source package.</P
><P
>To use any of the features listed, you should include a line in your
<TT
CLASS="FILENAME"
>sendmail.mc</TT
> that looks like:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>FEATURE(<TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
>)</PRE
></TD
></TR
></TABLE
>
where <TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
> is substituted with the feature name.
Some features take one optional parameter. If you wish to use
something other than the default, you should use an entry that looks like:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
>FEATURE(<TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
>, <TT
CLASS="REPLACEABLE"
><I
>param</I
></TT
>)</PRE
></TD
></TR
></TABLE
>
where <TT
CLASS="REPLACEABLE"
><I
>param</I
></TT
> is the parameter to supply.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14819"
>18.4.2.5. Local macro definitions</A
></H3
><P
>&#13;The standard <B
CLASS="COMMAND"
>sendmail</B
> macro configuration files provide
lots of hooks and variables with which you can customize your configuration.
These are called <B
CLASS="COMMAND"
>local macro definitions</B
>. Many of them
are listed in the <TT
CLASS="FILENAME"
>CF</TT
> file in the
<B
CLASS="COMMAND"
>sendmail</B
> source package.</P
><P
>The local macro definitions are usually invoked by supplying the name of the
macro with an argument representing the value you wish to assign to the
variable the macro manages. Again, we'll explore some of the more common
local macro definitions in the examples we present later in the chapter.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14829"
>18.4.2.6. Defining mail transport protocols</A
></H3
><P
>&#13;If you want <B
CLASS="COMMAND"
>sendmail</B
> to transport mail in any way other
than by local delivery, you must tell it which transports to use. The
<TT
CLASS="LITERAL"
>MAILER</TT
> macro makes this very easy. The current version of
<B
CLASS="COMMAND"
>sendmail</B
> supports a variety of mail transport protocols;
some of these are experimental, others are probably rarely used.</P
><P
>In our network we need the SMTP transport to send and receive mail
among the hosts on our local area network, and the UUCP transport to send
and receive mail from our smart host. To achieve this, we simply include both
the <TT
CLASS="LITERAL"
>smtp</TT
> and <TT
CLASS="LITERAL"
>uucp</TT
> mail transports. The
<TT
CLASS="LITERAL"
>local</TT
> mail transport is included by default, but may be
defined for clarity, if you wish. If you are including both the
<TT
CLASS="LITERAL"
>smtp</TT
> and the <TT
CLASS="LITERAL"
>uucp</TT
> mailers in your
configuration, you must always be sure to define the <TT
CLASS="LITERAL"
>smtp</TT
>
mailer first.</P
><P
>The more commonly used transports available to you using the
<SPAN
CLASS="SYSTEMITEM"
>MAILER</SPAN
> macro are described in the
following list:
<P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="SYSTEMITEM"
>local</SPAN
></DT
><DD
><P
> This transport includes both the local delivery agent used to send
mail into the mailbox of users on this machine and the
<SPAN
CLASS="SYSTEMITEM"
>prog</SPAN
> mailer used to send messages
to local programs. This transport is included by default.
</P
></DD
><DT
><SPAN
CLASS="SYSTEMITEM"
>smtp</SPAN
></DT
><DD
><P
> This transport implements the Simple Mail Transport Protocol (SMTP),
which is the most common means of transporting mail on the Internet.
When you include this transport, four mailers are configured:
<TT
CLASS="LITERAL"
>smtp</TT
> (basic SMTP), <TT
CLASS="LITERAL"
>esmtp</TT
> (Extended SMTP), <TT
CLASS="LITERAL"
>smtp8</TT
> (8bit binary clean SMTP),
and <TT
CLASS="LITERAL"
>relay</TT
> (specifically designed for gatewaying
messages between hosts).
</P
></DD
><DT
><SPAN
CLASS="SYSTEMITEM"
>uucp</SPAN
></DT
><DD
><P
> The <SPAN
CLASS="SYSTEMITEM"
>uucp</SPAN
> transport provides
support for two mailers:
<SPAN
CLASS="SYSTEMITEM"
>uucp-old</SPAN
>, which is the
traditional UUCP, and
<SPAN
CLASS="SYSTEMITEM"
>uucp-new</SPAN
>, which allows multiple
recipients to be handled in one transfer.
</P
></DD
><DT
><SPAN
CLASS="SYSTEMITEM"
>usenet</SPAN
></DT
><DD
><P
> This mailer allows you to send mail messages directly into
Usenet style news networks. Any local message directed to an address
of <I
CLASS="EMPHASIS"
>news.group.usenet</I
> will be fed into the
news network for the <I
CLASS="EMPHASIS"
>news.group</I
> newsgroup.
</P
></DD
><DT
><SPAN
CLASS="SYSTEMITEM"
>fax</SPAN
></DT
><DD
><P
> If you have the HylaFAX software installed, this mailer will
allow you to direct email to it so that you may build an email-fax
gateway. This feature is experimental at the time of writing and more
information may be obtained from
<SPAN
CLASS="SYSTEMITEM"
>http://www.vix.com/hylafax/</SPAN
>.
</P
></DD
></DL
></DIV
></P
><P
>There are others, such as the <SPAN
CLASS="SYSTEMITEM"
>pop</SPAN
>,
<SPAN
CLASS="SYSTEMITEM"
>procmail</SPAN
>,
<SPAN
CLASS="SYSTEMITEM"
>mail11</SPAN
>,
<SPAN
CLASS="SYSTEMITEM"
>phquery</SPAN
>, and
<SPAN
CLASS="SYSTEMITEM"
>cyrus</SPAN
> that are useful, but less
common. If your curiosity is piqued, you can read about these
in the sendmail book or the documentation supplied in the source package.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN14889"
>18.4.2.7. Configure mail routing for local hosts</A
></H3
><P
>&#13;The Virtual Brewery's configuration is probably more complex than most sites
require. Most sites today would use the SMTP transport only and do not
have to deal with UUCP at all. In our configuration we've configured a
&#8220;smart host&#8221; that is used to handle all outgoing mail.
Since we are using the SMTP transport on our local network we must tell
<B
CLASS="COMMAND"
>sendmail</B
> that it is not to send local mail via the
smart host. The <TT
CLASS="LITERAL"
>LOCAL_NET_CONFIG</TT
> macro allows you to
insert sendmail rules directly into the output <TT
CLASS="FILENAME"
>sendmail.cf</TT
>
to modify the way that local mail is handled. We'll talk more about rewrite
rules later on, but for the moment you should accept that the rule we've
supplied in our example specifies that any mail destined for hosts in the
<SPAN
CLASS="SYSTEMITEM"
>vbrew.com</SPAN
> domain should be delivered
directly to the target hosts using the SMTP mail transport.</P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x14644.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x14903.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Overview of Configuration Files</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="x-087-2-sendmail.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Generating the sendmail.cf File</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>