1

I try add route with redirect based on mx record.

But my regexp never work.

Exim 4.90, os ubontu 18.04.

My config:

non_mydom_mx:
  driver     = manualroute
  #condition = ${lookup dnsdb{mxh=^mx\d\.mydom\.net}{true}fail}
  condition  = ${lookup dnsdb{mxh=^.*\$}{true}fail}
  transport  = non_mydom
  route_list = * 192.168.0.11

Test routing failed:

mk@mydom.net
    <-- mk@mydom.net
  router = dnslookup, transport = remote_smtp
  host mx1.mydom.net [xxxx] MX=10
  host mx2.mydom.net [xxxx] MX=20
1

There are a few problems here. The lesser one is that the $ at the end of the regexp is not escaped, so exim thinks it is a beginning of a variable. This makes the expression fail to expand.

The bigger problem is that the dnsdb lookup does a simple DNS query, and that's it. Giving regexp in the lookup makes no sense, since that way, the query would be ambiguous. In your case, the lookup is something like "give me an MX address, I don't care which", and it obviously doesn't work. Even if you escape the $ sign, exim doesn't even expand the given regexp, instead tries to lookup the MX record for the host named ^.*$.

Routing based on the MX record can be done this way:

non_mydom_mx:
   driver     = manualroute
   condition = ${if match {${lookup dnsdb{>: mxh=$domain}}}{[^:]\d\.mydom\.net}{yes}{no} }
   transport  = non_mydom
   route_list = * 192.168.0.11

Here, you query the MX host name for the recipient domain. Since a domain tends to have more MX records, the lookup concatenates the results, separated by : (this is specified by the >: at the beginning of the lookup value). The value given by the dnsdb lookup is used in a match, which compares the result to a regexp (which considers the : character as beginning of a new line). If the result matches, then the condition results a yes, otherwise, a no, in which case the router declines.

It might worth mentioning that exim has an excellent debugging output, so if you are stuck, just start exim in debug mode like this:

exim4 -d+all -bd -oX 25252 2>&1|tee exim-debuglog.txt

After this, connecting to the given port (25252) and trying to send a simple message will make exim write all information about processing the message, including ACLs, routers, and the stages of variable expansions. It might come in handy if you try to figure out why a certain rule is not working.

1
  • Thank you +100500 times! That is what I need. I was feeling "if" construction need to use, but exim's sintax is not user friendly. – Terentev Maksim May 26 '20 at 14:35

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.