Nigel Metheringham edited this page Nov 29, 2012 · 2 revisions

Q0405

Question

On a host that accepts mail for several domains, do I have to use fully qualified addresses in /etc/aliases or do I have to set up an alias file for each domain?

Answer

You can do it either way. The default aliasing router contains this line:

data = ${lookup{$local_part}lsearch{/etc/aliases}}

which is what does the actual lookup. To make it look up the complete address instead of just the local part, use

data = ${lookup{$local_part@$domain}lsearch{/etc/aliases}}

If you want to use a separate file for each domain, use

data = ${lookup{$local_part}lsearch{/etc/aliases/$domain}}

A convenient cut-and-paste solution

domain_aliases:
  debug_print           = "domain_aliases for $local_part@$domain"
  driver                = redirect
  allow_defer           = yes
  allow_fail            = yes
  data                  = ${lookup{$local_part}lsearch*{${lookup{$domain}partial-lsearch{DOMAINDIR/map}\
                                   {DOMAINDIR/$value}} }}
  domains               = partial-lsearch;DOMAINDIR/map
  retry_use_local_part  = yes

This router has a directory DOMAINDIR (you can use that as a macro or replace the three occurrences of the macro in the router). DOMAINDIR/map maps a domain to a file name (domain: filename), while DOMAINDIR/filename is the actual alias file. That way, you can map multiple domains to the same alias file.

DOMAINDIR/map
example.com: example1
example.org: example2
example.net: example2
example.biz: example3

DOMAINDIR/example1
user1: bill

DOMAINDIR/example2
user2: alison

DOMAINDIR/example3
*: bill

that way, `user1@example.com`_ gets delivered to bill, while `user2@example.org`_ and `user2@example.net`_ both get delivered to alison, with all other combinations being handed down to the next router.

In the last example any messages sent to example.biz (like `santa.claus@example.biz`_) will be delivered to bill. Note: This catches ALL messages sent to example.biz. It might and probably will also increase the amount of incoming spam

**-------------------------

`Navigation(siblings)`_

-------------------------**

FAQ_ / `Routing for local delivery`_ **/ Q0405

-------------------------**

CategoryFrequentlyAskedQuestions_

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.