Centos – Exim address rewrite is not working

centosemailexchangeeximrewrite

after I could not get my Postfix server to do a proper rewrite, I tried to use an Exim server instead, but I am failing again on a simple rewrite.

I have used a default configuration, added my variables into it and created a new router for delivery to my both local mail servers on my private network. This router is the first in the processing line and configured this way:

manualroute_domains:
  driver = manualroute
  domains = lsearch;/etc/exim/relay_hosts
  route_data = ${lookup{$domain}lsearch{/etc/exim/relay_hosts}}
  transport = remote_smtp
  verify_recipient = false
  verify_sender    = false

A Testmail from domain1 to domain2 was successfully delivered.

Now I started to create my first rewriting rule at the "begin rewrite" block:

user1@domain1.com user1@newcorp.com SFfrs

A Test wirh exim -brw user1@domain1.com results in exactly the way I want my domain being rewritten, but when I try to send a mail from domain1, with the gateway as my smarthost, it always is received with the domain1.com ending and the new address is nowhere found in the header of the mail.

Is it possible, that I need to declare the use of rewriting in my router somewhere? I want to add conditions on my rewriting, so the use of header_rewrite on the router is no option for me.

Thank you all in advance for any idea or thought regarding my configuration!

With best regards
TooCloudy

Best Answer

You are rewriting at the wrong time. The S rewrite option specifies rewriting incoming addresses as they received. The pattern must match the whole address received in the MAIL FROM command. You likely want to rewrite when the headers are read during data processing.

Please be aware that the rewritten addresses may trigger SPAM avoidance measures. In particular, the SPF records for the domain are likely not to include your host as a permitted sender.

Try using a rewrite rule something like:

*@example.com      $1@example.net       Ffrs

If you want to rewrite individual addresses use /etc/email-aliases which will use one of these rewrite rules.

*@+local_domains "${lookup{${local_part}}lsearch{/etc/email-addresses}\
               {$value}fail}" Ffrs
*@ETC_MAILNAME "${lookup{${local_part}}lsearch{/etc/email-addresses}\
               {$value}fail}" Ffrs

You may need to create the /etc/email-addresses. Although it is commonly supported, it is rarely used. The above rules will work if your senders are all in the local domain(s) and should be rewritten for all local domains.

If you need to rewrite depended on the domain as well as the local_part, you need to configure for virtual domains. If you have a defined a domain list virtual_domains the following rewrite rule should rewrite based on email-alias format files in /etc/exim4/virtual with names like email-example.com.

*@+virtual_domains "${lookup{${local_part}}lsearch{/etc/exim4/virtual/email-${domain}}\
               {$value}fail}" Ffrs

Alternatively, you could match domain qualified addresses like user@example.com in the /etc/aliases file using a rule like:

*@+local_domains "${lookup{${local_part}@${domain}}lsearch{/etc/email-addresses}\
               {$value}fail}" Ffrs

You can test your rewrite rules as documented in the Exim4 Specification rewrite chapter with a command like:

exim -brw ph10@exim.workshop.example

Both alias and etc-aliases should contain lines like:

local_user:  new_user@example.net