0

domain.com and domain.net are hosted on one and the same server server1. To avoid SPAM and viruses all outgoing emails (even to local domains) are subjects to scan with a 3rd party service. Thus email from mail@domain.com to mail@domain.net should leave the server1, then it will be checked outside the server1, and then be delivered according to its MX record to server1, from which it was originated.

And here we end with a loop: Too many "Received" headers - suspected mail loop.

And here is what I have:

smarthost_relay:
   driver = manualroute
   ignore_target_hosts = 127.0.0.0/8
   condition = ${if !inlist{$sender_host_address}{<; 46.xxx.xxx.xxx }}
   condition = ${if or {{!eq{$sender_address}{}} {!eq{$sender_host_address}{}}}}
   condition = '${perl{check_limits}}'
   transport = auth_relay
   route_list = $domain 46.xxx.xxx.xxx::587
   same_domain_copy_routing = yes
   no_more

The $sender_host_address does not work here as I'd expected. As it's empty when an email arrives after a remote check. What do I miss? How to accomplish it?

Regards, Alex.

Alex
  • 75
  • 6

2 Answers2

2

You may want to set an ACL variable in an ACL during message processing to indicate that the message was received from the SPAM filter. There are several ACLs that are normally undefined that you can use for this. An ACL block something like this should detect the spam filter by IP or DNS name:

warn
  hosts = 46.xxx.xxx.xxx : spamfilter.example.com
  set acl_c9 = SPAMFiltered
  logwrite = Received from SPAM Filter server

Then use a simple check of the variable in the transport.

 condition = ${if eq {$acl_c9}{}}

You can remove the log_write from the ACL once you know it is working.

For this to work you need to ensure that you aren't using TURN or ETRN to receive mail back on the connection you used to send the message for spam filtering.

If you want to try modifying your conditions you may want to look at the match_ip operator instead of in_list.

To filter out messages routing within the same domain try a router condition like:

domains = ! $sender_address_domain
BillThor
  • 27,737
  • 3
  • 37
  • 69
  • Thanks for pointing me to the right direction. By the way it should be `logwrite` without underscore. – Alex Mar 18 '17 at 05:29
0

I've added the following lines in acl_check_mail:

warn    hosts = ! 46.xxx.xxx.xxx
          set acl_m_filtered = 0
          add_header = X-Received-SPAM-Filtered: $acl_m_filtered

warn    hosts = 46.xxx.xxx.xxx
          set acl_m_filtered = 1
          add_header = X-Received-SPAM-Filtered: $acl_m_filtered

and use condition = ${if eq {$acl_m_filtered}{0}{yes}{no}} check in my router.

No loops so far ;)

Alex
  • 75
  • 6
  • Additionally had to update `acl_not_smtp` an ACL for non-SMTP messages to set my variable `set acl_m_filtered = 0`. Without it when a message was submitted locally (that is, not over a TCP/IP connection) it arrived to local INBOX without remote check with a filter. – Alex Mar 20 '17 at 16:38