Which User Should Really Receive The Mail?
After checking the contents of the virtusertable, sendmail checks the aliases files to determine the ultimate recipient of mail.
The /etc/mail/virtusertable file
The /etc/mail/virtusertable file contains a set of simple instructions on what to do with received mail. The first column lists the target email address and the second column lists the local user's mail box, a remote email address, or a mailing list entry in the /etc/aliases file to which the email should be forwarded.
If there is no match in the virtusertable file, sendmail checks for the full email address in the /etc/aliases file.
firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org error:nouser User unknown
In this example, mail sent to:
- email@example.com will go to local user (or mailing list) webmasters, all other mail to another-site.com will go to local user marc.
- sales at my-site.com will go to the sales department at my-othersite.com.
- paul and finance at my-site.com goes to local user (or mailing list) paul
All other users at my-site.com receive a bounce back message stating "User unknown".
Note: Be sure to run the activate-sendmail.sh script from the beginning of the chapter for these changes to take effect.
The /etc/aliases File
You can think of the /etc/aliases file as a mailing list file. The first column has the mailing list name (sometimes called a virtual mailbox), and the second column has the members of the mailing list separated by commas.
To start, sendmail searches the first column of the file for a match. If there is no match, then sendmail assumes the recipient is a regular user on the local server and deposits the mail in their mailbox.
If it finds a match in the first column, sendmail notes the nickname entry in the second column. It then searches for the nickname again in the first column to see if the recipient isn't on yet another mailing list.
If sendmail doesn't find a duplicate, it assumes the recipient is a regular user on the local server and deposits the mail in their mailbox.
If the recipient is a mailing list, then sendmail goes through the process all over again to determine if any of the members is on yet another list, and when it is all finished, they all get a copy of the e-mail message.
In the example that follows, you can see that mail sent to users bin, daemon, lp, shutdown, apache, named, and so on by system processes will all be sent to user (or mailing list) root. In this case, root is actually an alias for a mailing list consisting of user marc and firstname.lastname@example.org.
# Basic system aliases -- these MUST be present.mailer-daemon: postmasterpostmaster: root# General redirections for pseudo accounts.bin: rootdaemon: root......abuse: root# trap decode to catch security attacksdecode: root# Person who should get root's mailroot: marc,email@example.com
Notice that there are no spaces between the mailing list entries for root: You will get errors if you add spaces.
Note: The default /etc/aliases file installed with RedHat / Fedora has the last line of this sample commented out with a #, you may want to delete the comment and change user marc to another user. Also after editing this file, you'll have to convert it into a sendmail readable database file named /etc/aliases.db. Here is the command to do that:
[root@bigboy tmp]# newaliases
In this simple mailing list example, mail sent to root actually goes to user account marc and firstname.lastname@example.org. Because aliases can be very useful, here are a few more list examples for your /etc/aliases file.
- Mail to "email@example.com" goes to users "peter", "paul" and "mary".
# Directors of my SOHO companydirectors: peter,paul,mary
- Mail sent to "firstname.lastname@example.org" goes to users "grandma", "brother" and "sister"
# My familyfamily: grandma,brother,sister
- Mail sent to admin-list gets sent to all the users listed in the file /home/mailings/admin-list.
# My mailing list fileadmin-list: ":include:/home/mailings/admin-list"
The advantage of using mailing list files is that the admin-list file can be a file that trusted users can edit, user root is only needed to update the aliases file. Despite this, there are some problems with mail reflectors. One is that bounce messages from failed attempts to broadcast go to all users. Another is that all subscriptions and unsubscriptions have to be done manually by the mailing list administrator. If either of these are a problem for you, then consider using a mailing list manager, such as majordomo.
One important note about the /etc/aliases file: By default your system uses sendmail to mail system messages to local user root. When sendmail sends e-mail to a local user, the mail has no To: in the e-mail header. If you then use a mail client with a spam mail filtering rule to reject mail with no To: in the header, such as Outlook Express or Evolution, you may find yourself dumping legitimate mail.
To get around this, try making root have an alias for a user with a fully qualified domain name, this forces sendmail to insert the correct fields in the header; for example:
# Person who should get root's mailroot: email@example.com
Note: Be sure to run the newaliases command for these changes to take effect.