12.6 Prevent Aliasing with -n
At times it is desirable to run
sendmail
so that it does not perform aliasing. When aliasing is disabled,
sendmail
uses the recipient address as is. No addresses are ever
The
-n
command-line switch
12.6.1 Is an Alias Bad?
In tracking down local delivery problems, it can be difficult to determine where the problem lies. If you suspect a bad alias, you can force aliasing to be
% /usr/sbin/sendmail -n user < /dev/null
This tells
sendmail
to send an empty mail message (one containing mandatory headers only) to the recipient named
user
. The
-n
Other switches, such as -v (verbose) and -d (debugging), can be combined with -n to view the delivery process in more detail. 12.6.2 Filtering Recipients with a Shell ScriptThe -n command-line switch can also be used to suppress aliasing when delivering to a list of recipients that has already been aliased. For example, consider the following script, which attempts to restrict delivery to users who have mail delivered locally and to skip users who have mail forwarded offsite:
#!/bin/sh
EX_OK=0 # From <sysexits.h>
EX_NOUSER=67 # From <sysexits.h>
EX_SOFTWARE=70 # From <sysexits.h>
if [ ${#} -ne 2 ]; then
echo Usage:
The sendmail program is called twice inside this script. First, it is given the -bv switch, which causes it to expand the list of recipients in $1 . That expansion includes aliasing (and ~/.forward aliasing) for each name in the list. The output produced looks like this: user1... deliverable: mailer local, user user1 user2@otherhost... deliverable: mailer smtp, host otherhost, user user2@otherhost The grep (1) program selects only those lines that contain the expression "mailer local" , thus indicating a local user. The sed (1) program then discards from the ... to the end of each selected line. The result, a list of local recipients only, is saved in the shell variable LIST .
The
sendmail
program is called with the
-n
switch, which prevents it from re-aliasing the list of
Note that this script should not be used as is because it checks only for the delivery agent named local , rather than for any delivery agent that can perform final delivery. |