Search code examples
configurationexim

Exim config rewrite rule allowing FROM any user @ their domain only?


I'm looking for a solution to replace cPanel's "Rewrite From Header" tweak, because I have one or possibly more client(s) with LOCAL Microsoft Exchange servers running in their office and they want to SMTP through our server. The problem is: MS Exchange only uses a SINGLE SMTP user no matter how many email accounts it holds.

cPanel's "Rewrite From Header" tweak rewrites all FROM addresses to match the actual sender, therefore in case of a local MS Exchange server, say [email protected] authenticates to our SMTP and then sends an email FROM [email protected] then our server rewrites it back to [email protected] and so forth for all email users.

This is normally a good thing, but this MS Exchange server needs to be able to send as [email protected], [email protected], [email protected] even if the only authentication they can do is with [email protected]

I took a look at exim rewrite patterns but I have zero experience with it, so any help in writing a generic rewrite rule to solve the following two conditions at once would be very much appreciated and could be beneficial and used by thousands of other web servers too...

REWRITE RULE CONDITIONS I NEED:

1) PHP scripts cannot forge FROM headers as an account's domain the script does not originate from. This is already achieved by cPanel's "Rewrite From Header" tweak.

2) External SMTP users can only forge FROM headers as the account's domain they authenticated with, meaning they could send FROM [email protected]. This is against cPanel's "Rewrite From Header" tweak.

So I need a combination/adaptation of cPanel's tweak to allow for the 2 conditions at once.

Thx


Solution

  • I ended up writing my own Perl script and annexing it to WHM's "Rewrite From: header" tweak found in /etc/exim.pl.local