Exim4: Catchall outgoing mail, allow only a few domains to pass through on a dev server

exim

Im administering a bunch of development and staging debian (v.6-8) servers. The current exim4 setup looks like this:

  • There are no incoming mails on the servers (no wan connection)
  • Outgoing mails are send via a smarthost (this is currently working)

Since the stage and dev servers email functionality will be tested through web apps and there are real world scenario email addresses set up in our web applications,
The setup that I want to achive is:

  • All outgoing mails should be forwarded by a catchall statement to one
    single email address, for example devmail@1234oursmarthost.com
  • All outgoing mails, that contain our companies domains, like *@example.com and *@foo.com should bypass the catchall rule.

The tutorial, that is closest to my goal is this, even if it uses the opposite
strategy: Allow all senders and deny one sender.

https://serverfault.com/a/577007/322673

Any help is really appreciated, since I'm going to be nuts on exim config syntax.

I'd been through a whole lot a configuration samples for days now, but none of them are matching my use case.

Best Answer

As Exim processes mail in the order specified in the routers section, I guess it can be achieved with the following rules. Be sure to put rule for the special domains first and then the catch all rules.

# sender domain based routing
router_for_special_domain_sender:
     driver = dnslookup
     senders =  *@example.com 
     transport = remote_smtp
     no_more 

# reciepients domain based routing
router_for_special_domain_reciepints:
     driver = dnslookup
     domains =  example.com 
     transport = remote_smtp
     no_more 

catch_all_outgoing:
     driver = redirect
     data = catchallemail@example.com

According to Exim documentation:

domains

If the domains option is set, the domain of the address must be in the set of domains that it defines.

senders

If this option is set, the router is skipped unless the message’s sender address matches something on the list. See section 3.12 for a list of the order in which preconditions are evaluated.

The first rule above tells exim to send all emails with a sender domain example.com to be sent without doing anything special. The second rule is a catch all for all emails. You can give it a try.

Here is the relevant discussion: http://www.gossamer-threads.com/lists/exim/users/97056