Exclude Email Account from System Filter Rule

vponteras

Member
May 16, 2017
15
0
1
Philippines
cPanel Access Level
Root Administrator
Hi All,

I have a system filter rule in /etc/cpanel_exim_system_filter_custom and it is currently working now.

Code:
if (
  $h_to: does not contain "our-domain.com" and
  $h_to: does not contain "allowed-domain1.com" and
  $h_to: does not contain "allowed-domain2.com" and
  $h_to: does not contain "allowed-domain3.com" and
  $h_to: does not contain "allowed-domain4.com"
  )
  and
  ($h_from: contains "our-domain.com")
then
  fail text "Unauthorized Mail"
endif
Now, I want an email account that will get excluded from that filter rule. For example all email account from @our-domain.com cannot send mails except for those domains our-domain.com, allowed-domain1.com, allowed-domain2.com, allowed-domain3.com and allowed-domain4.com but I want the email account [email protected] excluded on that filter rule and can send to all domains.

Please help :(
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
Hello,

You could try adding a separate filter rule ahead of the existing one that allows the message to proceed if it matches the specific condition you want to whitelist. Use the "Stop Processing Rules" action on the new filter rule so that the additional filter rules are not processed. Here's a document you may find helpful:

How to Configure Mail Filters - cPanel Knowledge Base - cPanel Documentation

Thank you.
 

vponteras

Member
May 16, 2017
15
0
1
Philippines
cPanel Access Level
Root Administrator
How do I position the filter rule? Is it before the fail rule or after it? Will this do?

Code:
# Block all except for listed domains
if (
  $h_to: does not contain "our-domain.com" and
  $h_to: does not contain "allowed-domain1.com" and
  $h_to: does not contain "allowed-domain2.com" and
  $h_to: does not contain "allowed-domain3.com" and
  $h_to: does not contain "allowed-domain4.com"
  )
  and
  ($h_from: contains "our-domain.com")
then
  fail text "Unauthorized Mail"
endif

# Exclude email account from block all rule
if ($h_from: contains "[email protected]")
  and
  ($h_to: contains "@")
then
  finish
endif
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
Hello,

You'd actually want to add the new rule before the existing rule. Here's an example of how it should look:

Code:
#123
if
 $header_from: matches "[email protected]"
then
 finish
endif
Thank you.
 

vponteras

Member
May 16, 2017
15
0
1
Philippines
cPanel Access Level
Root Administrator
Hi Michael, will this do?

Code:
if
  ($h_from: matches "[email protected]")
then
  finish
    elif
      (
        $h_to: does not contain "our-domain.com" and
        $h_to: does not contain "allowed-domain1.com" and
        $h_to: does not contain "allowed-domain2.com" and
        $h_to: does not contain "allowed-domain3.com" and
        $h_to: does not contain "allowed-domain4.com"
       )
      and
       ($h_from: contains "our-domain.com")
    then
      fail text "Unauthorized Mail"
    endif
endif
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
Hello,

That looks like a single rule. You should try setting up multiple rules first, like you started in your previous example.

Thank you.