Exim4: Receive and forward email for multiple domains
From your description, it appears you should be configuring your server as the primary MX for your clients' domains. There are a few addresses that likely should be delivered to you such as abuse
, postmaster
, webmaster
and hostmaster
. These should be handled by the default /etc/aliases
file.
The default configuration only uses the local part to lookup aliases. You will need to handle your clients messages specially. As you are forwarding to Gmail, you may want to remail the message rather than forwarding it. This should deal with SPF and DMARC issues.
Where your are the secondary MX, the variable you need to set is dc_relay_domains
. This should be a list of the domains you will be accepting email for as a secondary MX delimited by (':'). Whitespace is optional, but make the list easier to read.
The documentation for the file is available with the command man update-exim4.conf
. You may also want become familiar with the Specification of the Exim Mail Transfer Agent document.
The command sudo dpkg-reconfigure exim4-config
will provide a guided update of the /etc/exim4/update-exim4.conf.conf
. However, you can edit the file by hand if you wish.
You may want to add the domains you are a secondary MX for to /etc/exim4/local_rcpt_callout. Please read the documentation to verify if this is appropriate. Bouncing mail for the domains you are secondary for after you have accepted the message is likely to generate back-scatter spam. This may get your server blacklisted.
The default configuration does not support domain names in the aliases file. I use the following to provide domain based aliases, although you likely should not have aliases for the domains you are a secondary MX for.
# 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 vdomain_aliases: debug_print = "R: vdomain_aliases for $local_part@$domain" driver = redirect allow_fail allow_defer domains = dsearch;/etc/exim4/virtual data = ${lookup{$local_part}lsearch*@{/etc/exim4/virtual/$domain}} qualify_preserve_domain
This is a summary of @BillThor's answer, with some added detail:
Step 1
Edit /etc/exim4/update-exim4.conf
and set dc_other_hostnames
to include all the domains you will be forwarding mail for. (If you forget to do this, messages will be bounced).
Step 2
Create a directory /etc/exim4/virtual
and add one file per domain, named exactly the domain name. Fill the files with the aliases you wish to forward. For example
# File: /etc/exim4/virtual/example.com
# This will forward [email protected] to [email protected]
me: [email protected]
# This will forward [email protected] to [email protected]
postmaster: [email protected]
Step 3
Create a new file /etc/exim4/conf.d/router/350_local-config_vdomain_aliases
, with the content:
# 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
vdomain_aliases:
debug_print = "R: vdomain_aliases for $local_part@$domain"
driver = redirect
allow_fail
allow_defer
domains = dsearch;/etc/exim4/virtual
data = ${lookup{$local_part}lsearch*@{/etc/exim4/virtual/$domain}}
qualify_preserve_domain
Step 4
Run:
update-exim4.conf
service exim4 restart
Thanks for all your help @BillThor