28.3. Sendmail Configuration

Contributed by Christopher Shumway.

sendmail(8) is the default MTA which is installed with FreeBSD. Sendmail accepts mail from MUAs and delivers it to the appropriate mailer as defined by its configuration file. Sendmail can also accept network connections and deliver mail to local mailboxes or to another program.

Sendmail uses the following configuration files. This section describes these files in more detail.

FilenameFunction
/etc/mail/accessSendmail access database file.
/etc/mail/aliasesMailbox aliases
/etc/mail/local-host-namesLists of hosts Sendmail accepts mail for.
/etc/mail/mailer.confMailer program configuration.
/etc/mail/mailertableMailer delivery table.
/etc/mail/sendmail.cfSendmail master configuration file.
/etc/mail/virtusertableVirtual users and domain tables.

28.3.1. /etc/mail/access

This database defines which host(s) or IP addresses have access to the local mail server and what kind of access they have. Hosts can be listed as OK, REJECT, or RELAY, or can be passed to Sendmail's error handling routine with a given mailer error. Hosts that are listed as OK, which is the default option, are allowed to send mail to this host as long as the mail's final destination is the local machine. Hosts that are listed as REJECT are rejected for all mail connections. Hosts that are listed as RELAY are allowed to send mail for any destination using this mail server.

Example 28.1. Configuring the Sendmail Access Database
cyberspammer.com 550 We do not accept mail from spammers FREE.STEALTH.MAILER@ 550 We do not accept mail from spammers another.source.of.spam REJECT okay.cyberspammer.com OK 128.32 RELAY

This example shows five entries. Mail senders that match the left side of the table are affected by the action on the right side of the table. The first two examples give an error code to Sendmail's error handling routine. The message is sent to the remote host when a mail matches the left side of the table. The third entry rejects mail from a specific host on the Internet, another.source.of.spam. The fourth entry accepts mail connections from okay.cyberspammer.com, which is more specific than the cyberspammer.com line above. More specific matches override less exact matches. The last entry allows relaying of email from hosts with an IP address that begins with 128.32. These hosts can send mail through this mail server that is destined for other mail servers.

Whenever this file is updated, run make in /etc/mail/ to update the database.

28.3.2. /etc/mail/aliases

This database contains a list of virtual mailboxes that are expanded to other user(s), files, programs, or other aliases. Here are a few examples to illustrate the file format:

Example 28.2. Mail Aliases
root: localuser ftp-bugs: joe,eric,paul bit.bucket: /dev/null procmail: "|/usr/local/bin/procmail"

The mailbox name on the left side of the colon is expanded to the target(s) on the right. The first entry expands the mailbox root to the mailbox localuser, which is then looked up again in the aliases database. If no match is found, the message is delivered to localuser. The second entry shows a mail list. Mail to the mailbox ftp-bugs is expanded to the three local mailboxes joe, eric, and paul. A remote mailbox could be specified as . The third entry shows how to write mail to a file, in this case /dev/null. The last entry demonstrates how to send mail to a program, /usr/local/bin/procmail, through a UNIX® pipe.

Whenever this file is updated, run make in /etc/mail/ to update the database.

28.3.3. /etc/mail/local-host-names

This is a list of hostnames sendmail(8) is to accept as the local host name. Place any domains or hosts that Sendmail will receive mail for. For example, to configure a mail server to accept mail for the domain example.com and the host mail.example.com, add these entries to local-host-names:

example.com mail.example.com

Whenever this file is updated, sendmail(8) needs to be restarted so that it will read the changes.

28.3.4. /etc/mail/sendmail.cf

This is the master configuration file for Sendmail. It controls the overall behavior of Sendmail, including everything from rewriting email addresses to printing rejection messages to remote mail servers. Accordingly, this configuration file is quite complex. Fortunately, this file rarely needs to be changed for standard mail servers.

The master Sendmail configuration file can be built from m4(1) macros that define the features and behavior of Sendmail. Refer to /usr/src/contrib/sendmail/cf/README for some of the details.

Whenever changes to this file are made, Sendmail needs to be restarted for the changes to take effect.

28.3.5. /etc/mail/virtusertable

The virtusertable maps mail addresses for virtual domains and mailboxes to real mailboxes. These mailboxes can be local, remote, aliases defined in /etc/mail/aliases, or files.

Example 28.3. Example Virtual Domain Mail Map
root@example.com root postmaster@example.com postmaster@noc.example.net @example.com joe

The above example contains a mapping for the domain example.com. This file is processed in a first match order. The first item maps to the local mailbox root. The second entry maps to the mailbox postmaster on the host noc.example.net. Finally, if nothing from example.com has matched so far, it will match the last mapping, which matches every other mail message addressed to someone at example.com to the local mailbox joe.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.