None

Virtual Hosts Exim4 on Debian Lenny

March 19, 2010

virtual_hosts directory

In here, create a file for each hostname (for example drumcoder.co.uk). In each file, have a list of email accounts on the left, and local users or email addresses on the right, separated by a colon.

For example:

*:drumcoder
coder:me@here.com
freddy:fred
spamtrap:

The first line sends all emails that otherwise don't match anything in this file to the local user called drumcoder. The second line redirects any emails addressed to coder@domain to . The third line sends any emails addressed to freddy@domain to the local user fred. The final line rejects emails addressed to spamtrap@domain and returns them as undelivered.

exim4.conf.template

Modify the domainlist.local_domains to point at the virtual_hosts directory

domainlist local_domains = @:localhost:dsearch;/etc/exim4/virtual_hosts

Add another router to handle the virtual hosts

#####################################################
### router/350_exim4-config_vdom_aliases
#####################################################

vdom_aliases:
  debug_print = "R: vdom_aliases for $local_part@$domain"
  driver = redirect
  allow_defer
  allow_fail
  domains = dsearch;/etc/exim4/virtual_hosts
  data = ${expand:${lookup{$local_part}lsearch{/etc/exim4/virtual_hosts/$domain}}}
  retry_use_local_part
  pipe_transport   = address_pipe
  file_transport   = address_file

vdom_aliases_suffix:
  debug_print = "R: vdom_aliases_suffix for $local_part@$domain"
  driver = redirect
  local_part_suffix = +*
  local_part_suffix_optional
  allow_defer
  allow_fail
  domains = dsearch;/etc/exim4/virtual_hosts
  data = ${expand:${lookup{$local_part}lsearch*@{/etc/exim4/virtual_hosts/$domain}}}
  retry_use_local_part
  pipe_transport = address_pipe
  file_transport = address_file
  no_more

#####################################################
### end router/350_exim4-config_vdom_aliases
#####################################################

The first one of these deals with the virtual hosts.

The second deals with aliases. For example, given a user set up in the alias file as drum, this router will send any email to drum+anything@domain to this user. This allows the user to have as many email addresses as they need without additional setup.