When you address a message, aliases can shorten the address and make it easier to remember.
Here's an example. You're working on a project with three other people, and you stay in touch by email. If you didn't use mail aliases, you might address a message to all of them like this:
To: email@example.com, uunet!abo!pxu341i, firstname.lastname@example.orgWhat a pain to type those addresses each time you want to send mail!
Instead, pick a name (an alias) for that group of addresses. Store that alias name and the addresses in an alias file, then tell the MH commands where your alias file is. After that, when you send mail, all you have to type is the alias name -- for example:
To: projectThe next three sections explain the syntax of an MH alias file, how to make MH commands use it, and how to list MH aliases. After that is a section about another kind of aliases, those handled by your system MTA.
project: email@example.com, uunet!abo!pxu341i, firstname.lastname@example.orgYour aliases file (or whatever you name it -- see the Section Naming MH Alias Files) can have as many entries as you need. Put one alias on each line. If an alias has lots of addresses in it, you can continue it on other lines by ending each line with a backslash (\), like this:
project: email@example.com, uunet!abo!pxu341i, \ firstname.lastname@example.org, email@example.com, \ firstname.lastname@example.orgYou don't need to indent the continuation lines, but I think it makes the meaning clearer.
Long alias files can be hard to maintain. ("Who is email@example.com, anyway, and why is that person in my alias file?") Adding comment lines and names can identify aliases and the addresses on them. The Example below shows how. A line that starts with a semicolon (;) is a comment. Legal RFC 822 syntax works for addresses in most cases, so you can include names. As above, indent continuation lines and end all but the last line of the alias with a backslash (\).
Example: An MH alias file with comments and real names
; ; BOOK REVIEWERS: ; rvwrs: Freida Kumzickle <firstname.lastname@example.org>,\ Ethel Michaelman <email@example.com>,\ "Dr. Mary Tallman" <firstname.lastname@example.org>,\ Harry Wielstrom <email@example.com>
Aliases can include other aliases. The other aliases must be listed later in the alias file. For example, the allgroups alias in this alias file would send to all the groups listed below it:
allgroups: mkt, sls, mgt mkt: randy, xandra sls: paula, nathan, will mgt: gilligan, ozzie, harrietBut in the following alias file, the allgroups alias would not work because mkt, sls, and mgt are listed before it:
mkt: randy, xandra
sls: paula, nathan, will
mgt: gilligan, ozzie, harriet
allgroups: mkt, sls, mgt ...this won't work
So, always list an alias before the other aliases it references.
Some mail transfer agents, such as sendmail, also have their own alias files (sendmail uses a file like /usr/lib/aliases or /etc/aliases). The Section Aliases in Your Transfer Agent introduces MTA aliases.
You can also use your personal or group alias files to send mail to users who are members of UNIX groups. (Primary group members are usually listed in the system /etc/passwd file. Secondary group members are listed in /etc/group.) For example, let's say that joeb, amyl, and edwina are primary members of the UNIX group named staff. If you put entries like these in your alias file:
gurus: +staff everyone: *and you addressed a message to gurus, it would be sent to everyone who is listed in the system /etc/passwd file as being a member of the UNIX staff group... that's joeb, amyl, and edwina.
If you sent mail to the alias everyone, it would go to every user who has an account on your computer.
These special alias entries depend on your operating system, local computer, and more... there are too many possibilities to explain thoroughly here. If you have questions and you understand UNIX pretty well, start with the mh-alias(5) manual page on your system -- it's terse, but it has examples. Otherwise, show this book to an expert on your computer for help -- or grab a manual that explains the user and group setup on your version of UNIX.
You can take a list of addresses from a file by using a left angle bracket (<) and a filename. Here's an example of a file named /usr/ourgroup/staff and how you could use its addresses in an alias named mygroup:
% cat /usr/ourgroup/staff berthab sherryo vickiz firstname.lastname@example.org % cat aliases mygroup: < /usr/ourgroup/staffAlways be sure to use an absolute pathname, starting with a slash (/), no matter where the address file is stored.
If you don't always use MH for sending mail (for instance, you might work on a set of machines, not all of which have MH) you can keep your aliases in the .mailrc format used by many other MUAs. Here's a sed command that creates an MH alias file from .mailrc. You could put this in a shell function or alias -- or a little shell script. The square brackets in the fourth -e expression contain single tab and space characters:
sed -e '/^set/d' -e '/^unset/d' -e '/^ignore/d' \ -e 's/alias [^ ]*/&:/' -e 's/^alias //' \ -e 's/#/;/' $HOME/.mailrc > /yourMHdir/aliasesAnother Section shows a way to send a message with only some of the addresses in an alias. Also see the ali command, which is good for testing your alias file. The whom command is another good way to test aliases.
% cd Mail % vi aliasesTell MH commands where your alias file is:
ali: -alias aliases send: -alias aliases whom: -alias aliases
ali: -alias aliases -alias /usr/groupproj/mh_aliases send: -alias aliases -alias /usr/groupproj/mh_aliases whom: -alias aliases -alias /usr/groupproj/mh_aliasesIf there's an alias with the same name in more than one file, MH will use the first alias it finds -- and it reads alias filenames left to right.
MH 6.8 and above accept multiple filenames in the MH profile Aliasfile: entry. In MH 6.7 through 6.7.2, you can only put one alias filename in the Aliasfile: entry. Other aliases have to be listed on the individual command entries. So in MH 6.7-6.7.2, the example above could look like:
Aliasfile: aliases ali: -alias /usr/groupproj/mh_aliases send: -alias /usr/groupproj/mh_aliases whom: -alias /usr/groupproj/mh_aliasesNote that there may be a system-wide alias file in the MH library directory named MailAliases. Where it is and what aliases it has depend on your system postmaster or system administrator. If MH is trying to find an alias, and if the alias isn't in any of your -alias files, it will search the system-wide file (if that file exists).
If your alias file is in a directory that's shared between more than one computer, through a networked filesystem (such as NFS), be careful about the files it refers to. For instance, in the examples above, let's say that you create your alias file on the host hosta where the directory /usr/groupproj exists. Your home directory and alias file are shared by hostb and hostc, but the /usr/groupproj directory is only available on hosta. So, the aliases in /usr/groupproj/mh_aliases may cause mail bounces if you send to them from hostb or hostc. There are plenty of workarounds -- including a different MH profile, with its own alias file entries, on each host (see the Section Multiple MH Sessions for tips on that).
% ali gurus danro, rada, rbwilbur, ahofIf you don't give it an alias name to list, ali will list all the MH aliases you can use.
The -user switch makes ali work in the opposite way: you give ali the address and it finds the aliases which contain that address.
The -list switch gives output in a column. It's used in shell programming and with commands like mhmail. Here's the previous example using -list:
% ali -list gurus danro rada rbwilbur ahofAfter it searches your alias file(s), the ali command automatically searches the system MH alias file if there is one. If you don't want it to do this, use the -noalias switch. You can type that on the command line or add it to your MH profile.
Your transfer agent's aliasing probably works about the same as MH alias files, though its syntax might be different. Also, the ali command won't show aliases in a system alias file (but whom -check might, depending on your transfer agent).
If everyone on your system uses MH, you can put system-wide aliases in the MH alias file. But if some people run other user agents, system-wide aliases should go in the transfer agent's alias file. Also, if you have an alias with many members, you might want to put it in the system alias file. That's because MH replaces the alias name with the expanded list of addresses, which can lead to some very large mail headers.
Finally, aliases that are set by the transfer agent are probably "visible" to users on other computers. For example, if the site foo.xxx.com put an alias called staff in its sendmail aliases file, then anyone in the world could mail to email@example.com and have it delivered to the addresses in that alias. MH aliases can't be used that way.
[Table of Contents] [Index] [Previous: Changing Default Editors] [Next: Header Fields and Addresses]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: Jerry Peek <firstname.lastname@example.org>