/etc/aliases vs virtusertable
I have a mail server running Sendmail that hosts multiple mail domains. So for instance, emails addressed to @aaa.com and @bbb.com are both going to this same server. All this time I am using /etc/mail/virtusertable
to manage the mappings of different users of different mail domains to different local accounts.
But now I have just found out /etc/aliases
might be doing the similar things.
- What is the different role of
/etc/aliases
and/etc/mail/virtusertable
? - What
aliases
can do but notvirtusertable
, and vise versa?
I have searched through the web but can't find any site that compares the differences in a very detailed way.
Solution 1:
Key differences between virtusertable and aliases in sendmail
virtusertable
provides one to one mapping of recipient address. aliases
provide one to many mapping (handy for mailing lists).
aliases
map "domain-less" recipient (recipients in local email domains with stripped domain part of email). virtusertable
maps full recipient address.
virtusertable
handles remapping of "all other/remaining addresses in email domain".
"virtusertable to alias" mapping may be used to get one to many mapping.
Wizard level hint: It is possible to make sendmail.cf handle aliases for full emails (user part and domain) but sendmail.cf generated using m4 files provided by sendmail.org does not handle it. Implementing it will not be very complicated but IMHO some unexpected "side effects" are guaranteed => proper testing period will be LONG.
Solution 2:
Short Answer:
Aliasing is the process of converting one local recipient name on the system into another and Aliasing occurs only on local names. Which means, the username
must be available via getpwnam from the password database:
e.g., the local password file /etc/passwd, NIS, and LDAP.
The sendmail virtusertable
feature enables support for the virtual users, meaning it maps non-system users.
I have quoted the following from here. Very well explained, please have look.
/etc/mail/aliases
This database file contains a list of virtual mailboxes that are expanded to users, files, programs, or other aliases. Here are a few entries to illustrate the file format:
root: localuser ftp-bugs: joe,eric,paul bit.bucket: /dev/null procmail: "|/usr/local/bin/procmail"
The mailbox name on the left side of the colon is expanded to the target(s) on the right. The first entry expands the root mailbox to the localuser mailbox, which is then looked up in the /etc/mail/aliases database. If no match is found, the message is delivered to localuser. The second entry shows a mail list. Mail to ftp-bugs is expanded to the three local mailboxes joe, eric, and paul. A remote mailbox could be specified as [email protected]. The third entry shows how to write mail to a file, in this case /dev/null. The last entry demonstrates how to send mail to a program, /usr/local/bin/procmail, through a UNIX® pipe. Refer to aliases(5) for more information about the format of this file.
/etc/mail/virtusertable
This database file maps mail addresses for virtual domains and users to real mailboxes. These mailboxes can be local, remote, aliases defined in /etc/mail/aliases, or files. This allows multiple virtual domains to be hosted on one machine.
The following example demonstrates how to create custom entries using that format:
[email protected] root [email protected] [email protected] @example.com joe
This file is processed in a first match order. When an email address matches the address on the left, it is mapped to the local mailbox listed on the right. The format of the first entry in this example maps a specific email address to a local mailbox, whereas the format of the second entry maps a specific email address to a remote mailbox. Finally, any email address from example.com which has not matched any of the previous entries will match the last mapping and be sent to the local mailbox joe.
Now a little more detailed answers to your questions:
- The aliases database file contains a list of virtual mailboxes that are expanded to users, files, programs, or other aliases.
- This virtuser database file maps mail addresses for virtual domains and users to real mailboxes. These mailboxes can be local, remote, aliases defined in /etc/mail/aliases, or files. This allows multiple virtual domains to be hosted on one machine.
- The sendmail virtusertable feature on the other hand configure support for the virtual user table. The virtual user table maps incoming mail destined for someuser@host to someotheruser@otherhost. One can think of this as an advanced mail alias feature, one that operates using not just the destination user, but also the destination domain. The key portion (on the left) must be either a full address (user, host, and domain name), or an address without a host part (just a domain).
Solution 3:
The main difference that I recall is that virtusertable
may contain domain information as well as user information; that is; [email protected]
and [email protected]
are both valid and distinct left-hand-sides in virtusertable
, but used together in aliases
they will produce a duplicate alias name
error.
That still leaves a whole group of entries that can legitimately go in either; my feeling is that one should use aliases
wherever possible, leaving virtusertable
for those things that are domain-specific.
bangal (q.v.) notes some more important differences, eg the ability to send email to pipes and files.
Solution 4:
Try this:
If your MTA server is the primary MX for a bunch of DOMAINS, you route them through virtusertable. Virtusertable allows you to pick-off individual destination emails such as "abuse@..." and "postmaster@" and forward everything else to a single mailbox or another server entirely with a different name but keeping everything left of the '@' intact. For example:
[email protected]: helpdesk <--- which could be in /etc/aliases to a list
[email protected]: [email protected] <--- specific destination
@xyz.com: %[email protected] <--- route everything else to another host`
Your /etc/aliases file is really for setting up simple destinations from one user to another or from one user to a group of other users:
root: [email protected] <--- route all root mail to sysadmin
sales: jdoe,mdoe,sone,[email protected],[email protected] <-- to a list
nobody: /dev/null <--- anything sent to "nobody" disappears forever
Aliases is not very good at handling multiple domains, on the other hand virtusertable is very good at it.
You will need to set up your MX records appropriate, etc.
Cheers, David