Solaris Advanced User's Guide

Mail Aliases

A mail alias is a selection of user names that are grouped under a single name.

Use mail aliases when you want to send messages to the same group of people over and over. For example, if you occassionally send mail to hank@fretful, george@lonesome, and sally@dakota, you could create a mail alias called amigos. Then, each time you sent mail to amigos, all three people would receive it.

Two locations where you can set up mail aliases are:

Mail aliases that are set up in .mailrc behave differently from mail aliases set up in /etc/aliases. These differences are summarized in Table 7-1 at the end of this section.

Setting Up Mail Aliases in .mailrc

Note the following about setting up mail aliases in .mailrc:

.mailrc is located in your home directory. This file contains several settings that control the behavior of mailx and Mail Tool.

To add a mail alias to .mailrc, type:


$ vi ~/.mailrc    

Note –

You can use any text editor to edit the .mailrc file. The previous example shows the method for using the vi editor to edit the file. If you are not already familiar with vi, refer to Chapter 6, Using the vi Editor for instructions.


Each mail alias is contained on one line of the file. That is, the line can visually “wrap around” to another line, but it cannot contain carriage returns. Each mail alias should contain the following, separated by spaces:

The following example shows two mail aliases. The first alias (amigos) contains three people. The second alias (softball) contains eight. Notice in softball how the names are visually wrapped around on the screen. This is fine, as long as no carriage returns are used.


alias amigos hank@fretful george@lonesome sally@dakota
alias softball earl@woofer tex@twister elmer@farmhouse
jane@freeway hank@fretful jj@walker sally@dakota steve@hardway

To send mail to people on a .mailrc alias, address the mail to the mail alias name. Do not include your machine name. Suppose that you sent the following message:


$ mail amigos
Subject: Let's eat

Hey Compadres. How about
getting together for lunch on Friday?
Anyone interested?

The recipients would see the following (note the expanded To: line):


To: hank@fretful george@lonesome sally@dakota
Subject: Let's eat

Hey Compadres. How about getting together for lunch on Friday?
Anyone interested?

Setting Up Mail Aliases in /etc/aliases

Note the following about setting up mail aliases in /etc/aliases:

The format of mail aliases that are created in /etc/aliases is somewhat different from those in .mailrc. Each /etc/aliases alias should use the following format:

To modify your /etc/aliases file, you must first become root. If root is password protected, you'll need to know the root password.

Type the following to become the root user on the system:


$ su
Password:
#

Notice that the command prompt changes when you become root.

The following example shows how the alias softball@texas is added to the default /etc/aliases file.


# vi /etc/aliases     
##
#Aliases can have any mix of upper and lower case on the left-
#hand side,
#but the right-hand side should be proper case (usually lower)
#
#     >>>>>>>>>>The program “newaliases” will need to be run after
#     >> NOTE >>this file is updated for any changes to
#     >>>>>>>>>>show through to sendmail.
#
#@(#)aliases 1.10 89/01/20 SMI
##
# Following alias is required by the mail protocol, RFC 822
# Set it to the address of a HUMAN who deals with this system's
mail problems.
Postmaster: root

# Alias for mailer daemon; returned messages from our MAILER-
DAEMON
# should be routed to our local Postmaster.
MAILER-DAEMON: postmaster

# Aliases to handle mail to programs or files, eg news or vacation
# decode: “|/usr/bin/uudecode”
nobody: /dev/null

# Sample aliases:
# Alias for distribution list, members specified here:
#staff:wnj,mosher,sam,ecc,mckusick,sklower,olson,rwh@ernie

# Alias for distribution list, members specified elsewhere:
#keyboards: :include:/usr/jfarrell/keyboards.list

# Alias for a person, so they can receive mail by several names:
#epa:eric

#######################
# Local aliases below #
#######################
softball@texas: earl@woofer
tex@twister elmer@farmhouse
jane@freeway hank@fretful jj@walker sally@dakota steve@hardway
:wq         (to quit viand save the  /etc/aliasesfile )
# exit      (to exit root)
$

You can use any text editor to edit the /etc/aliases file. The previous example shows the method for using the vi editor to edit the file. If you are not already familiar with vi, refer to Chapter 6, Using the vi Editor for instructions.

Note that the pound signs (#) you see within the /etc/aliases file have been placed there to comment out the text and sample aliases. The pound signs prevent the system from processing this information as actual aliases.

Do not place pound signs in front of aliases you add to this file, unless you intentionally want to disable an alias.

To send mail to people on a /etc/aliases alias, address the mail by using the name of the alias and your machine name. Suppose that you sent the following:


$ mail softball@texas
Subject: Practice Today

Let's meet at the diamond
behind Building 4 after work tonight.
Goodness knows we can use the practice for Saturday's game! Be
there as early as you can.

The recipients would see the following:


To: softball@texas
Subject: Practice Today

Let's meet at the diamond behind Building 4 after work tonight.
Goodness knows we can use the practice for Saturday's game! Be
there as early as you can.

Notice that the To: line is not expanded.

Whenever you send mail by using a mail alias of this type, be sure to include the machine name of the machine on which it's located. If you set up a mail alias called riders on the machine freeway, then you should send your mail to riders@freeway.

Table 7-1 provides a summary comparison between mail aliases that are created in .mailrc and those that are created in /etc/aliases.

Table 7–1 Comparing Mail Aliases in .mailrc and /etc/aliases

 

.mailrc

/etc/aliases

Must be root to modify?

no 

yes 

Send message to: 

alias

alias@machinename

Recipients list seen by recipients? 

yes 

no 

Names separated by commas? 

no 

yes 

Names all on one line? 

yes 

no 

Others can use the mail alias? 

no 

yes 

For more detailed information on mail aliases, type man aliases or man addresses at the system prompt.