2

Using exim4 I have set up a route to use an external SMTP server. I am using cPanel which keeps a list of domains set up locally on the server in the file: /etc/localdomains . As a result I have set up a condition to only send through this relay if the sender address domain is in this file. This works just fine.

However now I want to add another condition that ensures that if a domain is listed in a file say /etc/norelaydomains it should NOT be sent using the relay. I thought it would be an easy matter to get this to work by adding a similar condition to the one ensuring the domain is in /etc/localdomains, however this does not seem to work correctly (no mail sent using the relay).

To recap what I want is: if sender_domain is IN /etc/localdomains and sender_domain is NOT IN /etc/norelaydomains then send using relay, otherwise send using local mail server.

My normal setup that works fine is:

my_route:
  condition = ${lookup {$sender_address_domain} \ 
lsearch {/etc/localdomains} {yes}}
  driver = manualroute
  domains = !+local_domains
  transport = my_relay
  route_list = * mysmtp.com

The setup I have attempted (using this no mails go through the relay)

my_route:
  condition = ${lookup {$sender_address_domain} \ 
lsearch {/etc/localdomains} {yes}}
  condition = ${lookup{$sender_address_domain} \
lsearch{/etc/norelaydomains} {no}}
  driver = manualroute
  domains = !+local_domains
  transport = my_relay
  route_list = * mysmtp.com

Any help on getting this to work would be much appreciated.

1
  • Everything looks fine except the line splitting. Are you sure you haven't trailing spaces after ` \`?
    – Kondybas
    Oct 28, 2014 at 21:14

1 Answer 1

3

I've got it.

Your problem is in the incomplete result substitution.

${lookup{value}lsearch{file}} by default returns the string been found or the empty string. You can modify that behaviour by result substitution:

${lookup{value}lsearch{file}{yes}}

That version returns yes if value has been found in the file and the empty string otherwise. But exim's condition evaluation treat as logical TRUE only 'yes', 'true' and nonzero positives. Therefore

${lookup{value}lsearch{file}{no}}

is equivalent to the

${lookup{value}lsearch{file}{no}{no}}

Always. Sure, your router will never be used. You have to substitute both results explicitly:

my_route:
  condition = ${lookup {$sender_address_domain}lsearch{/etc/localdomains} {yes}{no}}
  condition = ${lookup {$sender_address_domain}lsearch{/etc/norelaydomains} {no}{yes}}
  driver = manualroute
  domains = !+local_domains
  transport = my_relay
  route_list = * mysmtp.com
0

Not the answer you're looking for? Browse other questions tagged .