Virtual domains with Exim 4 and Debian (updated)

This tutorial describes pretty well how to configure a default Exim setup (in Debian) to support a number of domains for local delivery (ie. if your mail server serves multiple domains). However the article is a bit outdated (last mod. was in 2006), so here's a short update.

First reconfigure Exim via dpkg:
dpkg-reconfigure exim4-config

You can answer the config split question ("Split configuration into small files?") as you wish, but for "General type of mail configuration" select "Internet site", for "System mail name" specify whatever domain you seem fit (I entered the hostname of the server, as returned by the hostname --long command), for "IP-addresses to listen on for incoming SMTP connections" enter nothing or at least the public IP of the server, leave the "Other destinations" empty. Answer the remaining questions as you see fit.

Now edit the /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs file and replace the domainlist local_domains = MAIN_LOCAL_DOMAINS line with:
domainlist local_domains = MAIN_LOCAL_DOMAINS : lsearch;/etc/exim4/domains.virtual

Create a a copy of the file /etc/exim4/conf.d/router/400_exim4-config_system_aliases and name it 410_exim4-config_virtual_aliases. In the copy replace the "system_aliases" string with "virtual_aliases", remove the line containing "domains = +local_domains", and replace the line starting with "data = ..." with this:
data = ${lookup{$local_part@$domain}lsearch{/etc/exim4/aliases.virtual}}

Now regenerate the Exim config template (/etc/exim4/exim4.conf.template):
update-exim4.conf.template -rn

And generate the final (working copy of the) Exim config:

You can now create a file at /etc/exim4/domains.virtual containing one domain (FQDN) in a line, and a file at /etc/exim4/aliases.virtual containing an "alias: user" in every line (where alias should contain the domain too).
Eg. thomas david
where thomas and david should be local users on the server, and and should be listed in /etc/exim4/domains.virtual.

Finally: restart Exim
invoke-rc.d exim4 restart

You can test whether you where successful with the exim -d -bt 2>&1 | more command. It provides in-depth details on how Exim tries to handle a mail coming to the given address.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

What about forwarding to other mail address?

Thanks for your article, it's really useful.
How can I redirect mesages to another accounts? For example, gmail addresses.

Re: What about forwarding to other mail address?

You've several options here.

Eg. you could put an email-address into the target of an item in the aliases file.
Normally you put lines like this into aliases:
email_alias_name: account_name
This would deliver emails coming to the "" to mail repository of the local account with name "account_name".

But you can also have lines like this:

This will forward all mail coming to "" to "".

Another option would be (if you have no admin control of the mail server, but just being a simple user) to create a .forward file in the HOME directory of the user (who receives the emails) and put the email address into that file. All mail will be forwarded to that address (at least with the default Exim configuration ... of course a sys admin can change that and disable .forward support).


Glad I found your blog , helped me to set up my Exim with virtual domains and aliases! It works! Smile

data =

data = ${lookup{$local_part@$domain}lsearch*{/etc/exim4/aliases.virtual}}

add '*' to allow such line in aliases.virtual:

* : :blackhole:

All mail to addresses unlisted in aliases.virtual will go to blackhole.

Syndicate content