25.7 The User's ~/.forward File
The
sendmail
program allows each user to have a
If a recipient address selects a delivery agent with the
If all the
.forward
files listed in the
forward: no home V8 sendmail temporarily transforms itself into the user [7] 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.
If
sendmail
can find and read the
~/.forward
file
and if that file is safe,
sendmail
opens the file for
reading and gathers a list of recipients from it.
Internally, the
~/.forward
file is exactly
the same as a
Beginning with V8
sendmail
,
~/.forward
files may contain
comments (lines that begin with a 25.7.1 Unscrambling Forwards
The traditional use of the
~/.forward
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
~/.forward
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 [8] to examine them. For example, consider a local user whose ~/.forward contains the following line:
user@remote.domain
This causes all local mail for the user to be forwarded to
the host
%
This shows that the user is known at 25.7.2 Forwarding LoopsBecause ~/.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:
\user, user@B Then, on machine B the user creates this ~/.forward file:
\user, user@A
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:
user: \user
This causes mail for 25.7.3 Appending to FilesThe ~/.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:
\user /home/user/mail/in.backup
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.
If the
\user /arch/bob.backup here /arch was specified by the SafeFileEnvironment option
When the 25.7.4 Piping Through Programs
The
~/.forward
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
sendmail
to skip additional alias transformations. For
The quotes around the
vacation
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
sendmail
, when mail was sent to
both
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"
25.7.5 Specialty Programs for Use with ~/.forwardRather 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. 25.7.5.1 The deliver program
The
deliver
(1) program, by
Chip Salzenberg, is specifically designed to
handle all types of final delivery for users. It is intended
for use in the
~/.forward
file but also functions
as a
"|/usr/local/bin/deliver user" The deliver program is available via anonymous FTP from many archive sites. 25.7.5.2 The procmail program
The
procmail
(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
the
"|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. 25.7.5.3 The slocal programThe 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 . 25.7.6 Force Requeue on Error
Normally, a program in the user's
~/.forward
file is executed
with the Bourne shell. The precise means that is used is defined by the
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"
Here, the |
|