HPlogo Installing and Administering Internet Services: HP 9000 Networking > Chapter 4 Installing 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 create the aliases database by adding aliases to the file /etc/mail/aliases and then running the newaliases script to generate the database from the file. The generated 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 his or her home directory. The .forward file allows the user to forward his or her own mail to files or to other mailing addresses.

This section contains the following task-related subsections:

Adding sendmail Aliases to the Alias Database

  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 add lines to the file. Each line has the following form:

    alias : mailing_list

    where alias is a 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 4-1 “Things That May Be Included in a Mailing List” lists the types of things you can include in a mailing list and the syntax for each one.

  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, which is located in the file /etc/mail/aliases.

Table 4-1 Things That May Be Included in a Mailing List

user_name

A local user name will be looked up in the aliases database unless you put a backslash (\) before it. To prevent sendmail from performing unnecessary alias lookups, put backslashes before local user names. 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). Example:

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

filename

An absolute pathname on the local machine. sendmail appends a 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 non-zero 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". 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 path name. Non-root users can create :include files for maintaining their own mailing lists. An :include file can contain anything that can be specified in the right side of an alias definition. Example alias definition:

dogbreeders: :include:/users/andrea/dogbreeders

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

Because the sender of a message often does not control the mailing list to which the message is addressed, sendmail allows you to configure an owner for a mailing list. 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 sendmail encountered while trying to deliver mail to the members of the chess_club mailing list would be reported to mike.

Avoiding Alias Loops

You should avoid creating aliasing loops. Loops can occur either locally or remotely. Following is an example of a local alias loop:

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

When regenerating the alias database, newaliases 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 only recipients for the message are in 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 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

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 30 tracing header lines have been added, sendmail recognizes the aliasing loop and aborts the delivery with an error message.

Creating a Postmaster Alias

RFC 822 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 HP-UX defines the postmaster to be 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 that your alias is valid:

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

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

Users can use the HP expand_alias utility to expand an alias or mailing list as far as is 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+

The sendmail aliases database can be managed through the Network Information Service (NIS or NIS+), which is one of the NFS Services. NIS or NIS+ 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 Installing and Administering NFS Services.

When you configure NIS or NIS+ in 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, make sure the /etc/mail/aliases file on the NIS or NIS+ master server contains all the sendmail aliases 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.

Rewriting the "From" Line on Outgoing Mail

HP provides a method that allows the "From" line on mail to be rewritten. This can be useful where 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 from "Bob_Kelley (maildrop)".

To rewrite "From" lines on outgoing mail:

  1. Create the file /etc/mail/userdb that contains two entries for each mail user who will have outgoing mail on the system. The entries should 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 will redirect mail addressed to you to the addresses in the .forward file.

A .forward file can contain anything that can appear on the right side of an alias definition, including programs and files. (See Table 4-1 “Things That May Be Included in a Mailing List” earlier in this chapter.) 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 as well as 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 an :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.

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