HPlogo HP-UX Mailing Services Administrator's Guide: HP-UX 11i v1 and HP-UX 11i v2 > Chapter 2 Configuring and Administering Sendmail

Creating Sendmail Aliases

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The Sendmail aliases database stores mailing lists and mail aliases. You must create the aliases database by adding aliases to the file /etc/mail/aliases and then by running the /usr/sbin/newaliases command to generate the database from the file. The generated alias database is stored in the file /etc/mail/aliases.db. The Sendmail startup script also generates the aliases database when you reboot your system.

Each user on your system can create a list of alternate mailing addresses in a .forward file in the user’s home directory. The .forward file allows users to forward their own mail to files or to other mailing addresses.

This section discusses the following topics:

NOTE: A non-root user does not have access to the files or databases associated with Sendmail namely: /etc/mail/aliases.*, /etc/mail/sendmail.st, and /etc/mail/sendmail.

Adding Aliases to the Sendmail Alias Database

To add Sendmail aliases to the database, follow these steps:

  1. If the file /etc/mail/aliases does not exist on your system, copy it from /usr/newconfig/etc/mail/aliases to /etc/mail/aliases.

  2. Use a text editor to edit the file. Each line is of the following form:

    alias : mailing_list

    where alias is the local address, local user name, or local alias, and mailing_list is a comma-separated list of local user names or aliases, remote addresses, file names, commands, or included files. Table 2-1 “Mailing List Options” describes the options that can be included in a mailing list.

  3. Issue the following command to regenerate the aliases database from the /etc/mail/aliases file:

    /usr/sbin/newaliases

    This command creates the aliases database located in /etc/mail/aliases.

Table 2-1 Mailing List Options

Option

Description

user_name

Sendmail looks up the aliases database for the local user name unless you put a backslash (\) before the local user name. To prevent Sendmail from performing unnecessary alias lookups, put backslashes before local user names. For example:

local_users: \amy, \carrie, \sandy, \anne,\david,\tony
remote_users: mike, denise
mike: mike@chem.tech.edu
denise: bigvax!amlabs!denise

remote_address

The remote address syntax that Sendmail understands is configured in the Sendmail configuration file and usually includes RFC 822 style addressing (user@domain) and UUCP style addressing (host!user). For example:

chess_club: mike@chem.tech.edu, marie@buffalo, bigvax!amlabs!denise

filename

An absolute pathname on the local machine. Sendmail appends the message to the file if the following conditions are true:

  • The file exists, is not executable, and is writable by all.

  • The directory where the file resides is readable and searchable by all. Example:

    public: /tmp/publicfile
    terminal: /dev/tty

Mail addressed to public is appended to /tmp/publicfile. Mail addressed to terminal appears on the sender’s terminal.

"| command"

Sendmail pipes the message as standard input to the specified command. The double quotes are required to protect the command line from being interpreted by Sendmail. Commands must be listed as full pathnames.

If stdout and stderr are not redirected, they are not printed to the terminal, and they disappear. However, if a command returns a nonzero exit status, its output to stderr becomes part of the Sendmail error transcript.

The command is executed by the prog mailer defined in the configuration file. In the configuration file supplied with HP-UX, the prog mailer is configured as “sh -c”. For example:

prog: "| / usr /bin/cat | / usr /bin/sed
       's/Z/z/g' > /tmp/outputfile"

Mail addressed to prog is saved in /tmp/outputfile with all capital Z’s changed to lowercase z’s.

:include:filename

Any mail addressed to the alias is sent to all the recipients listed in the included file. The file must be a full pathname. Nonroot users can create :include files to maintain their mailing lists. An :include file can contain anything that is specified in the right side of an alias definition. Following is an example alias definition:

dogbreeders: :include:/users/andrea/dogbreeders

Following is an example :include file:

#file included in dogbreeders alias definition: terriers@akc.ny.com, coonhounders@ukc.sc.com 

 

An alias can be continued across multiple lines in the aliases file. Lines beginning with blanks or tabs are continuation lines.

The aliases file can contain comment lines, which begin with the pound sign (#). Blank lines in the aliases file are ignored.

NOTE: You cannot address messages directly to file names, command lines, or :include files. Sendmail will deliver messages to these only if they appear in the right side of an alias definition.

Configuring Owners for Mailing Lists

Sendmail enables you to configure an owner for a mailing list, because the sender of a message often does not control the mailing list to which the message is addressed. If Sendmail encounters an error while attempting to deliver a message to the members of a mailing list, it looks for an alias of the form owner-mailing_list and sends the error message to the owner. For example, if mike were responsible for maintaining the chess_club mailing list, he could be configured as the owner:

chess_club:  mike@chem.tech.edu, marie@buffalo,
bigvax!amlabs!denise, margaret@hp.com
owner-chess_club:  mike@chem.tech.edu

Any errors that Sendmail encounters while trying to deliver mail to the members of the chess_club mailing list would be reported to mike.

Avoiding Alias Loops

You must avoid creating aliasing loops. Loops can occur either locally or remotely. An example of a local alias loop is as follows:

#Example of a local alias loop
first : second
second : first

While regenerating the alias database, the newaliases command does not notice a loop like the one shown in the previous example. However, after the alias database is generated, mail addressed to either first or second is not sent. If the recipients for the message are only in the local alias loops, the message is returned with the error message All recipients suppressed.

In the previous example, if mail is addressed to first, first expands to second, which expands back to first. This causes Sendmail to remove first from the recipient list as a duplicate.

# Example alias entry on host sage
dave : dave@basil
# Example alias entry on host basil
dave : dave@sage

The following is an example of a remote aliasing loop:

Mail sent to dave at either host sage or host basil bounces between the two systems. Sendmail adds a tracing header line (Received:) with each hop. When 26 tracing header lines have been added, Sendmail recognizes the aliasing loop and aborts the delivery with an error message.

Creating a Postmaster Alias

RFC 2822 requires that a postmaster alias be defined on every host. The postmaster is the person in charge of handling problems with the mail system on that host. The default aliases file supplied with the HP-UX operating system designates the postmaster as root. You can change this alias to the appropriate user for your system.

Verifying Your Sendmail Aliases

After you have created a Sendmail alias and regenerated the aliases database, issue the following command to verify the validity of your alias:

/usr/sbin/sendmail  -bv  -v  aliasalias, . . .

The -bv option causes Sendmail to verify the aliases without collecting or sending any messages. Any errors in the specified aliases are logged to standard output.

You can use the HP expand_alias utility to expand an alias or mailing list as far as possible. For more information on the expand_alias utility, type man 1M expand_alias at the HP-UX prompt.

Managing Sendmail Aliases with NIS or NIS+

You can manage the Sendmail aliases database through the Network Information Service (NIS or NIS+), which is one of the NFS Services. This service allows you to maintain an aliases database on one server system. All other systems request alias information from the server. In order to use NIS or NIS+, you must set up an NIS or NIS+ domain and configure the machines in your network as NIS or NIS+ servers and clients. For information about the NIS or NIS+ aliases database, see the manual Installing and Administering NFS Services, at the URL http://www.docs.hp.com/hpux/onlinedocs/B1031-90048/B1031-90048.html.

When you configure NIS or NIS+ on your network, it manages your Sendmail aliases by default, so you do not have to make any changes to your NIS or NIS+ configuration.

Before you run the NIS ypinit script or the NIS+ nispopulate script, ensure that the /etc/mail/aliases file on the NIS or NIS+ master server contains all the Sendmail aliases that you want to make globally available through NIS or NIS+.

The Sendmail program uses the Name Service Switch to determine where to look for Sendmail aliases.

Modifying your NIS Aliases Database

For information about the NIS or NIS+ aliases database, see Installing and Administering NFS Services, at the URL http://www.docs.hp.com/hpux/onlinedocs/B1031-90048/B1031-90048.html.

Rewriting the From Line on Outgoing Mail

HP provides a method that allows the From line on a mail message to be rewritten. This can be useful when a user’s login name does not clearly identify the user to intended mail recipients. For example, mail sent by bkelley (mailname) can be changed to read as Bob_Kelley (maildrop).

To rewrite From lines on an outgoing mail message, do the following:

  1. Create the file /etc/mail/userdb, which contains two entries for each mail user. The entries must be in the following format:

    bkelley:mailname      Bob_Kelley
    Bob_Kelley:maildrop   bkelley
  2. Build the /etc/mail/userdb.db file with the makemap routine:

    makemap btree /etc/mail/userdb.db < /etc/mail/userdb
  3. Uncomment the following line in the /etc/mail/sendmail.cf file:

    UserDatabaseSpec=/etc/mail/userdb.db
  4. Add the i flag to all the mailer definitions, to enable UDB sender rewriting. For example, change the mailer definition from

    Mlocal, P=/usr/bin/rmail, F=lsDFMAw5:/|@m,
    S=10/30, R=20/40, T=DNS/RFC822/X-Unix,
    A=rmail -d $u

    to

    Mlocal, P=/usr/bin/rmail, F=lsDFMAw5:/|@mi,
    S=10/30, R=20/40, T=DNS/RFC822/X-Unix,
    A=rmail -d $u
  5. Uncomment the first rule in ruleset 94.

Forwarding Your Own Mail with a .forward File

You can redirect your own mail by creating a .forward file in your home directory. If a .forward file exists in your home directory and is owned by you, Sendmail redirects mail addressed to you to the addresses that the .forward file contains.

A .forward file can contain anything that appears on the right side of an alias definition, including programs and files. (See Table 2-1 “Mailing List Options” earlier in this chapter.) The following is an example of a .forward file owned by user alice on host chicago:

alice@miami, alice@toronto, \alice,  mycrew

Mail sent to alice@chicago will be delivered to alice’s accounts on hosts miami and toronto, and to her account on local host chicago. It will also be delivered to all the recipients of the mailing list mycrew, which must be defined in the local aliases database or in the :include file on host chicago.

The aliases database is read before a .forward file. The .forward file is read only if the user’s name is not defined as an alias or if an alias expands to the user’s name.

© 2006 Hewlett-Packard Development Company, L.P.