Exim4 redirect mail sent to *@domain1.example.com to *@domain2.example.com

emailemail-servereximforwardingredirect

Current situation:
We have a VPS that hosts a website example.org. Exim is configured to work as a smarthost. All emails sent through exim are successfully relayed to another mail server (that is working on example.com).

Goal:
To forward mail sent to *@example.org to *@example.com, i.e. change the recipient's address from *@example.org to *@example.com.

Problem:
If I send email to address *@example.org, then it seems exim doesn't change the address, it still relays the message to another mail server but recipient is still *@example.org. Maybe the redirect is not applied for some reason.

Configuration and logs:

/etc/exim4/update-exim4.conf.conf:

dc_eximconfig_configtype='smarthost'
dc_other_hostnames=''
dc_local_interfaces=''
dc_readhost='example.org'
dc_relay_domains='example.org'
dc_minimaldns='false'
dc_relay_nets='0.0.0.0/32'
dc_smarthost='example.com::26'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='true'
dc_mailname_in_oh='true'
dc_localdelivery='maildir_home'

/etc/exim4/conf.d/router/999_exim4-config_redirect (created by me):

 domain_redirect:  
     debug_print = "R: forward for $local_part@$domain"  
     driver = redirect  
     domains = example.org
     data = it@example.com

(for now data is set to a specific address for simplicity and testing)

exim log when sending email to it@example.org (should be redirected to it@example.com):

2012-03-20 19:40:07 1SA4ud-0005Dw-7k <= test@example.org U=www-data P=local S=657
2012-03-20 19:40:08 1SA4ud-0005Dw-7k => it@example.org R=smarthost T=remote_smtp_smarthost H=domain2.com [184.172.146.66] X=TLS1.0:RSA_AES_256_CBC_SHA1:32 DN="C=US,2.5.4.17=#13053737303932,ST=TX,L=Houston,STREET=Suite 400,STREET=11251 Northwest Freeway,O=HostGator.com,OU=HostGator.com,OU=Comodo PremiumSSL Wildcard,CN=*.hostgator.com"
2012-03-20 19:40:08 1SA4ud-0005Dw-7k Completed

So, the address is not changed 🙁

Please help! I'm trying to make it work for half a day already 🙁

Solution:
So, aseq helped me to solve the problem. Although the solution looked a little bit weird to me. When I tried to set dc_use_split_config='true' it didn't help, it looked like my redirect file was not used. Also when I tried to add those redirect lines to the end of /etc/exim4/exim4.conf.template it didn't help either. But when I tried to paste those lines after "begin routers" line it finally worked!

Best Answer

Please use example.com instead of domain2.com, example.com (and .org .net) was specifically created for examples and documentation.

In your /etc/exim4/update-exim4.conf.conf you have configured:

dc_use_split_config='false'

However you are changing something in /etc/exim4/conf.d/router/999_exim4-config_redirect which will be ignored because you are not using split configuration.

Either do:

dc_use_split_config='true'

And reload exim4, you may prefer to change it using:

dpkg-reconfigure exim4-config

Or edit /etc/exim4/exim4.conf.template to add your customisations instead and reload exim4 once done.

Debian exim4 has a feature called hubbed_hosts which can be a convenient way to accomplish what you want without having to add your own routers et al.

So if your want your server to send email destined for domain example.org to domain example.com which has MTAs listening on IPs 192.0.2.1 and 192.0.2.10 you do the following:

  • Create /etc/exim4/hubbed_hosts and add:

    example.org: 192.0.2.1:192.0.2.10

  • reload exim4

Note, no spaces between the IP addresses and they're separated by a colon ':'

What this does is it will relay email destined for example.org to IPs 192.0.2.1,192.0.2.10 (in my example the IPs of example.com). It therefore will ignore the MX records of that domain. The IP address could be anything, as long as it is configured to receive those emails.

Finally there is address rewriting, see: http://www.exim.org/exim-html-current/doc/html/spec_html/ch31.html Perhaps it has something that will fit your requirements. You could use it in addition to hubbed_hosts.

Related Topic