program allows each user to have a
If a recipient address selects a delivery agent with the
If all the
files listed in the
forward: no home
V8 sendmail temporarily transforms itself into the user  before trying to read the ~/.forward file. This is done so that reads will work across NFS . If sendmail cannot read the ~/.forward file (for any reason), it silently ignores that file.
Before reading the ~/.forward file, sendmail checks to see whether it is a "safe" file - one that is owned by the user or root and that has the read permission bit set for the owner. If the ~/.forward file is not safe, sendmail silently ignores it.
can find and read the
and if that file is safe,
opens the file for
reading and gathers a list of recipients from it.
file is exactly
the same as a
Beginning with V8
files may contain
comments (lines that begin with a
The traditional use of the
file, as its name implies,
is to forward mail to another site. Unfortunately, as users move
from machine to machine, they can leave behind a series of
files, each of which points to the next machine in a chain.
As machine names change and as old machines are retired, the
links in this chain can be broken.
One common consequence is a bounced mail message ("host unknown")
with a dozen or so
As the mail administrator, you should beware of the ~/.forward files of users at your site. If any contain offsite addresses, you should periodically use the SMTP expn command  to examine them. For example, consider a local user whose ~/.forward contains the following line:
This causes all local mail for the user to be forwarded to
This shows that the user is known at
Because ~/.forward files are under user control, the administrator occasionally needs to break loops caused by improper use of those files. To illustrate, consider a user who wishes to have mail delivered on two different machines (call them machines A and B). On machine A the user creates a ~/.forward file like this:
Then, on machine B the user creates this ~/.forward file:
The intention is that the backslashed name (
On the machine that the administrator controls, a fix to this looping is to temporarily edit the aliases database and insert an alias for the offending user like this:
This causes mail for
The ~/.forward file can contain the names of files onto which mail is to be appended. Such filenames must begin with a slash character that cannot be quoted. For example, if a user wishes to keep a backup copy of incoming mail:
The first line (
Note that, prior to V8, sendmail did no file locking, so writing files by way of the ~/.forward file was not recommended. Beginning with V8, however, sendmail locks those files during writing, so such use of the ~/.forward file is now okay.
\user /arch/bob.backup here /arch was specified by the SafeFileEnvironment option
file can contain the names of programs
to run. A program name is indicated by a leading pipe (
\user, "|/usr/ucb/vacation user"
Recall that prefixing a local address with a backslash tells
to skip additional alias transformations. For
The quotes around the
program are necessary to prevent
the program and its single argument (
Beginning with V8 sendmail , a user must have a valid shell to run programs from the ~/.forward file. See Section 18.8.34, PATH... for a description of this process and for methods to circumvent it at the system level.
Because sendmail sorts all addresses and deletes duplicates before delivering to any of them, it is important that programs in ~/.forward files be unique. Consider a program that doesn't take an argument and suppose that two users both specified that program in their ~/.forward files:
user 1 \user1, "|/bin/notify" user 2 \user2, "|/bin/notify"
Prior to V8
, when mail was sent to
If a program requires no arguments (as opposed to ignoring them), the ~/.forward program specifications can be made unique by including a shell comment:
user 1 \user1, "|/bin/notify #user1" user 2 \user2, "|/bin/notify #user2"
Rather than expecting users to write home-grown programs for use in ~/.forward files, offer them any or all of the publicly available alternatives. The most common are listed below.
(1) program, by
Chip Salzenberg, is specifically designed to
handle all types of final delivery for users. It is intended
for use in the
file but also functions
The deliver program is available via anonymous FTP from many archive sites.
(1) program, by
Stephen R. van den Berg,
is purported to be the most
reliable of the delivery programs. It can sort incoming mail
into separate folders and files, run programs, preprocess mail (filtering
out unwanted mail), and selectively forward mail elsewhere.
It can function as a substitute for
"|exec /usr/local/bin/procmail #user"
Note that procmail does not accept a username as a command-line argument. Because of this, a dummy shell comment is needed for pre-V8 versions of sendmail to make the address unique. The procmail program is available via anonymous FTP from many archive sites.
The slocal program, distributed with the mh distribution, is useful for sorting incoming mail into separate files and folders. It can be used with both UNIX -style mail files and with mh -style mail directory folders. It is typically used in the ~/.forward file like this:
"| /usr/local/lib/mh/slocal -user user"
The disposition of mail is controlled using a companion file called ~/.maildelivery .
Mprog, P=/bin/sh, F=lsDFMeuP, S=10, R=20, A=sh -c $u The Bourne shell
One drawback to using the Bourne shell to run programs is that it exits with a value of 1 when the program cannot be executed. When sendmail sees the exit value 1, it bounces the mail message.
There will be times when bouncing a mail message because the program could not execute is not desirable. For example, consider the following ~/.forward file:
"| /usr/local/lib/slocal -user george"
If the directory /usr/local/lib is unavailable (perhaps because a file server is down or because an automounter failed), the mail message should be queued, rather than bounced. To arrange for requeueing of the message on failure, users should be encouraged to construct their ~/.forward files like this:
"| /usr/local/lib/slocal -user george || exit 75"