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 looked up in the aliases file, even if they are local.

The -n command-line switch tells sendmail not to perform aliasing of recipient addresses. This switch is rarely used but can be handy in a couple of situations.

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 skipped and see whether that causes the problem to go away:

% /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 prevents sendmail from looking up user either in the aliases database or in that user’s ~/.forward. If user resolves to the local delivery agent, the message will be delivered, and you should therefore suspect an aliasing problem.

Other switches, such as -v (verbose) and -d (debugging), can be combined with -n to view the delivery process in more detail.

Filtering Recipients with a Shell Script

The -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 ...

Get Sendmail, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.