FAQ / Routing for local delivery / Q0405



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



FAQ / Routing for local delivery / Q0405


CategoryFrequentlyAskedQuestions

EximWiki: FAQ/Routing_for_local_delivery/Q0405 (last edited 2008-09-25 11:39:34 by localhost)