Create or modify email aliases for Sendmail or Postfix

Author: Cezary Morga cm@therek.net FreeBSD

Reviewer: name contact BSD flavour

Reviewer: name contact BSD flavour


Concept

Understand when to create an email alias and how to do so for either Sendmail or Postfix.

Introduction

It is frequent situation that being a system administrator you have to receive information sent to couple of e-mail addresses, like ex. admin@mydomain.net, abuse@mydomain.net or hostmaster@mydomain.net. One way of doing so is maintaining an e-mail account for each address and frequently checking all of them for new mail. Although it would work, in the long run it would cause unnecessary complication to the e-mail account system. The other way is using mail aliases.

E-mail alias is an entry in aliases file. It explains to MTA which existing e-mail account should receive mail bound for given e-mail address. It is useful for both permanent and temporary aliases, as well as for keeping small mailing lists. Some e-mail aliases are required by RFC 2142.

Both Postfix and Sendmail use the /etc/mail/aliases file to define e-mail aliases. The file format is similar for both MTAs. The names of existing accounts and aliases can be specified without trailing @ and domain name for local accounts.

The MTA actually does not read directly from /etc/mail/aliases file. Instead, it reads information from /etc/mail/aliases.db, the random access data base. Thus after every modification of the file aliases the data base has to be rebuild by simply executing command newaliases(1). There is no need to restart the MTA daemon.

Postfix, as an addition, includes a postalias(1) command for creating, quering or updating alias databases. To see given alias entry execute postalias with -q flag followed by an alias name. Please note, that it have to be a name used as a key in alias database.

Examples

Within the /etc/mail/aliases file aliases are specified in the format of <alias name>: <existing account>. The <existing account> should be substituted by one or more account names in form of a coma separated list. The <alias name> acts as a key in alias database.

Sample alias for an administrator that should receive root's mail:

""root: mike

Sample alias for an e-mail admin@mydomain.net that should be delivered to all the administrators:

""admin: mike, john, stacy

Now, let's say we have three senior administrators: Mike, John, Stacy, and also two junior administrators: Jane, and Paul. All of them should receive mail from admin account, but only senior administrators should receive mail also from root and abuse accounts. Furthermore, there's also Jake who should receive abuse information as well. Alias configuration should look like this:

""root: senior ""abuse: root, jake ""admin: senior, junior ""senior: mike, john, stacy ""junior: jane, paul

Practice Exercises

  1. Add practice alias pointing to your own account, rebuild data base and check whether you'll receive mail sent to this account.
  2. With Postfix MTA use postalias(1) to display given (-q flag), and all (-s flag) entries in alias database.

More information

newaliases(1), aliases(5), postalias(1)