📄 sendmail.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>sendmail Configuration</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Electronic Mail" href="mail.html" /><link rel="PREVIOUS" title="Using Electronic Mail" href="mail-using.html" /><link rel="NEXT" title="Changing Your Mail Transfer Agent"href="mail-changingmta.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="mail-using.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 22 Electronic Mail</td><td width="10%" align="right" valign="bottom"><a href="mail-changingmta.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="SENDMAIL" name="SENDMAIL">22.3 <bclass="APPLICATION">sendmail</b> Configuration</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> ChristopherShumway.</i> <p><a href="http://www.FreeBSD.org/cgi/man.cgi?query=sendmail&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendmail</span>(8)</span></a> is thedefault Mail Transfer Agent (MTA) in FreeBSD. <b class="APPLICATION">sendmail</b>'s jobis to accept mail from Mail User Agents (<acronym class="ACRONYM">MUA</acronym>) anddeliver it to the appropriate mailer as defined by its configuration file. <bclass="APPLICATION">sendmail</b> can also accept network connections and deliver mail tolocal mailboxes or deliver it to another program.</p><p><b class="APPLICATION">sendmail</b> uses the following configuration files:</p><div class="INFORMALTABLE"><a id="AEN32020" name="AEN32020"></a><table border="0" frame="void" class="CALSTABLE"><col /><col /><thead><tr><th>Filename</th><th>Function</th></tr></thead><tbody><tr><td><tt class="FILENAME">/etc/mail/access</tt> </td><td><b class="APPLICATION">sendmail</b> access database file</td></tr><tr><td><tt class="FILENAME">/etc/mail/aliases</tt> </td><td>Mailbox aliases</td></tr><tr><td><tt class="FILENAME">/etc/mail/local-host-names</tt> </td><td>Lists of hosts <b class="APPLICATION">sendmail</b> accepts mail for</td></tr><tr><td><tt class="FILENAME">/etc/mail/mailer.conf</tt> </td><td>Mailer program configuration</td></tr><tr><td><tt class="FILENAME">/etc/mail/mailertable</tt> </td><td>Mailer delivery table</td></tr><tr><td><tt class="FILENAME">/etc/mail/sendmail.cf</tt> </td><td><b class="APPLICATION">sendmail</b> master configuration file</td></tr><tr><td><tt class="FILENAME">/etc/mail/virtusertable</tt> </td><td>Virtual users and domain tables</td></tr></tbody></table></div><div class="SECT2"><h2 class="SECT2"><a id="AEN32058" name="AEN32058">22.3.1 <ttclass="FILENAME">/etc/mail/access</tt></a></h2><p>The access database defines what host(s) or IP addresses have access to the local mailserver and what kind of access they have. Hosts can be listed as <varclass="OPTION">OK</var>, <var class="OPTION">REJECT</var>, <varclass="OPTION">RELAY</var> or simply passed to <b class="APPLICATION">sendmail</b>'serror handling routine with a given mailer error. Hosts that are listed as <varclass="OPTION">OK</var>, which is the default, are allowed to send mail to this host aslong as the mail's final destination is the local machine. Hosts that are listed as <varclass="OPTION">REJECT</var> are rejected for all mail connections. Hosts that have the<var class="OPTION">RELAY</var> option for their hostname are allowed to send mail forany destination through this mail server.</p><div class="EXAMPLE"><a id="AEN32069" name="AEN32069"></a><p><b>Example 22-1. Configuring the sendmail Access Database</b></p><pre class="PROGRAMLISTING">cyberspammer.com 550 We don't accept mail from spammersFREE.STEALTH.MAILER@ 550 We don't accept mail from spammersanother.source.of.spam REJECTokay.cyberspammer.com OK128.32 RELAY</pre></div><p>In this example we have five entries. Mail senders that match the left hand side ofthe table are affected by the action on the right side of the table. The first twoexamples give an error code to <b class="APPLICATION">sendmail</b>'s error handlingroutine. The message is printed to the remote host when a mail matches the left hand sideof the table. The next entry rejects mail from a specific host on the Internet, <ttclass="HOSTID">another.source.of.spam</tt>. The next entry accepts mail connections froma host <tt class="HOSTID">okay.cyberspammer.com</tt>, which is more exact than the <ttclass="HOSTID">cyberspammer.com</tt> line above. More specific matches override lessexact matches. The last entry allows relaying of electronic mail from hosts with an IPaddress that begins with <tt class="HOSTID">128.32</tt>. These hosts would be able tosend mail through this mail server that are destined for other mail servers.</p><p>When this file is updated, you need to run <tt class="COMMAND">make</tt> in <ttclass="FILENAME">/etc/mail/</tt> to update the database.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN32082" name="AEN32082">22.3.2 <ttclass="FILENAME">/etc/mail/aliases</tt></a></h2><p>The aliases database contains a list of virtual mailboxes that are expanded to otheruser(s), files, programs or other aliases. Here are a few examples that can be used in<tt class="FILENAME">/etc/mail/aliases</tt>:</p><div class="EXAMPLE"><a id="AEN32087" name="AEN32087"></a><p><b>Example 22-2. Mail Aliases</b></p><pre class="PROGRAMLISTING">root: localuserftp-bugs: joe,eric,paulbit.bucket: /dev/nullprocmail: "|/usr/local/bin/procmail"</pre></div><p>The file format is simple; the mailbox name on the left side of the colon is expandedto the target(s) on the right. The first example simply expands the mailbox <ttclass="USERNAME">root</tt> to the mailbox <tt class="USERNAME">localuser</tt>, which isthen looked up again in the aliases database. If no match is found, then the message isdelivered to the local user <tt class="USERNAME">localuser</tt>. The next example shows amail list. Mail to the mailbox <tt class="USERNAME">ftp-bugs</tt> is expanded to thethree local mailboxes <tt class="USERNAME">joe</tt>, <tt class="USERNAME">eric</tt>, and<tt class="USERNAME">paul</tt>. Note that a remote mailbox could be specified as <varclass="LITERAL">user@example.com</var>. The next example shows writing mail to a file, inthis case <tt class="FILENAME">/dev/null</tt>. The last example shows sending mail to aprogram, in this case the mail message is written to the standard input of <ttclass="FILENAME">/usr/local/bin/procmail</tt> through a <spanclass="TRADEMARK">UNIX</span>® pipe.</p><p>When this file is updated, you need to run <tt class="COMMAND">make</tt> in <ttclass="FILENAME">/etc/mail/</tt> to update the database.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN32105" name="AEN32105">22.3.3 <ttclass="FILENAME">/etc/mail/local-host-names</tt></a></h2><p>This is a list of hostnames <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendmail&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendmail</span>(8)</span></a> is toaccept as the local host name. Place any domains or hosts that <bclass="APPLICATION">sendmail</b> is to be receiving mail for. For example, if this mailserver was to accept mail for the domain <tt class="HOSTID">example.com</tt> and the host<tt class="HOSTID">mail.example.com</tt>, its <tt class="FILENAME">local-host-names</tt>might look something like this:</p><pre class="PROGRAMLISTING">example.commail.example.com</pre><p>When this file is updated, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sendmail&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sendmail</span>(8)</span></a> needs tobe restarted to read the changes.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN32121" name="AEN32121">22.3.4 <ttclass="FILENAME">/etc/mail/sendmail.cf</tt></a></h2><p><b class="APPLICATION">sendmail</b>'s master configuration file, <ttclass="FILENAME">sendmail.cf</tt> controls the overall behavior of <bclass="APPLICATION">sendmail</b>, including everything from rewriting e-mail addresses toprinting rejection messages to remote mail servers. Naturally, with such a diverse role,this configuration file is quite complex and its details are a bit out of the scope ofthis section. Fortunately, this file rarely needs to be changed for standard mailservers.</p><p>The master <b class="APPLICATION">sendmail</b> configuration file can be built from <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=m4&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">m4</span>(1)</span></a> macros thatdefine the features and behavior of <b class="APPLICATION">sendmail</b>. Please see <ttclass="FILENAME">/usr/src/contrib/sendmail/cf/README</tt> for some of the details.</p><p>When changes to this file are made, <b class="APPLICATION">sendmail</b> needs to berestarted for the changes to take effect.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN32137" name="AEN32137">22.3.5 <ttclass="FILENAME">/etc/mail/virtusertable</tt></a></h2><p>The <tt class="FILENAME">virtusertable</tt> maps mail addresses for virtual domainsand mailboxes to real mailboxes. These mailboxes can be local, remote, aliases defined in<tt class="FILENAME">/etc/mail/aliases</tt> or files.</p><div class="EXAMPLE"><a id="AEN32143" name="AEN32143"></a><p><b>Example 22-3. Example Virtual Domain Mail Map</b></p><pre class="PROGRAMLISTING">root@example.com rootpostmaster@example.com postmaster@noc.example.net@example.com joe</pre></div><p>In the above example, we have a mapping for a domain <ttclass="HOSTID">example.com</tt>. This file is processed in a first match order down thefile. The first item maps <var class="LITERAL">root@example.com</var> to the localmailbox <tt class="USERNAME">root</tt>. The next entry maps <varclass="LITERAL">postmaster@example.com</var> to the mailbox <ttclass="USERNAME">postmaster</tt> on the host <tt class="HOSTID">noc.example.net</tt>.Finally, if nothing from <tt class="HOSTID">example.com</tt> has matched so far, it willmatch the last mapping, which matches every other mail message addressed to someone at<tt class="HOSTID">example.com</tt>. This will be mapped to the local mailbox <ttclass="USERNAME">joe</tt>.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="mail-using.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="mail-changingmta.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Using Electronic Mail</td><td width="34%" align="center" valign="top"><a href="mail.html" accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Changing Your Mail Transfer Agent</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting <<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>>.<br />For questions about this documentation, e-mail <<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>>.</small></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -