I'm tying to setup exim4 as MTA for multidomain host. All users and domains are virtual, stored in the database like that:

create table emails
domain varchar(200),
username varchar(200),
password varchar(200)

Mesages are stored in the maildirs:

directory = /var/spool/mail/$domain/$local_part

I have multiple domains, like private.tld, company1.tld and company2.tld. I want to setup exim to handle company1 and company2 domains like company1, and want, as well, to handle subdomains, like www.private.tld as private.tld. And I need this to be performed for every user, without explicit aliases for each user. As I understand, I need to make a kind of domain aliases, so I created the table:

create table domains_aliases
  source_domain varchar(300),
  replacement_domain varchar(300)

And added select source_domain from domains_aliases to the MAIN_LOCAL_DOMAINS. And now I'd like to write a rule with condition for domains, listed in this table, probably like that (not sure):

condition=${lookup sql{select source_domain from domain_aliases where source_domain=${quote_sql:$domain}}{{yes}{no}}}

And perform replacement then - change $domain to select replacement_domain from domains_aliases where source_domain='${quote_sql:$domain}' I searched docs but did not find how to make this. Maybe some headers_rewrite? Cannot find this in the documentation, it's a bit unclear for me, please help.

Update: Just realized that it is possible to make driver=redirect for something like select $loacl_part@replacement_domain from domain_aliases where source_domain=$domain, but maybe there's a better way?

  • Exim doc contains specific examples for virtual domains, see chapter 50 (some common configuration settings) section 7 (virtual domains), for example. The net is also full of examples.
    – grin
    Commented Jan 11, 2019 at 10:45
  • @grin could you pls show me one related to the question I asked?
    – BUKTOP
    Commented Jan 11, 2019 at 11:03
  • exim.org/exim-html-current/doc/html/spec_html/… 7. virtual domains show an example with redirect, or like in p5r.uk/blog/2002/virtual_domains.html
    – grin
    Commented Jan 11, 2019 at 11:13
  • @grin Did you read the question? ))) well, nevermind, I already did it a long time ago as described in the question
    – BUKTOP
    Commented Jan 11, 2019 at 11:17

1 Answer 1


Normally, you want to set the domain to the appropriate domain for the server. You are likely leaving the envelope domain set to the "qualify_domain" setting. You may need to configure your server for virtual hosts. (Users need to be in the appropriate domain alias file.) I have the following router to handle virtual domains.

# This router handles aliasing using traditional /etc/aliases type files.
#### NB  You must ensure that /etc/exim/virutual/${domain} file exist
#### This works with the standard "name : destination" alias format

# Domain aliases
  debug_print = "R: vdomain_aliases for $local_part@$domain"
  driver = redirect
  domains = dsearch;/etc/exim4/virtual
  data = ${lookup{$local_part}lsearch*@{/etc/exim4/virtual/$domain}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .