1

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

2
  • What conditions do you intend to add? You have the S flag set which means this rule fires at SMTP time before exim even decides what $local_part and $domain might be, which would likely make it hard to set any conditions. See exim.org/exim-html-current/doc/html/spec_html/… – DerfK Apr 24 '17 at 2:08
  • Good to know, thank you! I want to do a conditional rewrite in the following way: If dom1 to dom2 or dom2 to dom1 don't do a rewrite. If mime is encrypted or signed dont do a rewrite. If both prior rules were not applied, do a rewrite incoming and outgoing on a fixed filetable list. – TooCloudy Apr 24 '17 at 6:45
1

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
2
  • That is strange, when I use the wildcard, the rewrite is applied without any problems. Unfortunately I need to rewrite the domain on a sender dependent list and cannot use wildcards. :( A file named /etc/email-aliases cannot be found on my system (CentOS 7.3), but I do have a router "system_aliases" with a lookup into the direction data = ${lookup{$local_part}lsearch{/etc/aliases}}. Is this the correct file? – TooCloudy Apr 24 '17 at 6:45
  • @TooCloudy No, /etc/aliases is not the correct file. It is for addresses being delivered to. It alters the list of addresses being delivered too without a rewrite. This is standard email functionality. I've updated my answer with more details on /etc/email-aliases. man etc-alias may provide a man page for aliases and email-aliases. – BillThor Apr 24 '17 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.