SOLVED Exim Deny All Except

vponteras

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

I want outgoing messages for our domain (our-domain.com) blocked except for other other domains. I tried the suggested exim filter from cPanelMichael but it's not working.

I want our-domain to blocked from all domains but still can send to our-domain.com, allowed1.com and allowed2.com

Here is my exim filter

Code:
if
  $header_from: contains "@our-domain" and
  $header_to: does not contain "@out-domain" or
  $header_to: does not contain "@allowed1.com" or
  $header_to: does not contain "@allowed2.com"
then
  fail text "Unauthorized Mail"
endif
Please help
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

Could you also outline the specific steps you have taken thus far to implement that custom filter rule?

Note the email filter options in cPanel are designed to filter incoming email. You can customize the Exim system filter if you want to apply a filter to outgoing email. Information about modifying the Exim system filter is documented at:

How to Customize the Exim System Filter File - cPanel Knowledge Base - cPanel Documentation

Thank you.
 

vponteras

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

I am using the system filter /etc/cpanel_exim_system_filter_custom.

I want block all incoming and outgoing mails except for our domain, allowed1.com and allowed2.com.

Because we're planning to have our mails for company mails only and prevent incoming mails except for allowed1.com and allowed2.com

What should be the suitable filter for that setup?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

The rules in your initial post look okay. In "WHM >> Exim Configuration Manager", under the "Filters" tab, are you using a custom filter for the "System Filter File" option? If so, you'd need to add your custom filter rules to that custom system filter file itself instead of adding them as separate filter files under the options directory. There's a thread on this topic at:

Exim custom filter not working

Thank you.
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
465
113
UK
cPanel Access Level
Root Administrator
In a normal account filter rule, the 'or' operator does not work using <does not contain>. I don't know about the custom rules for exim outgoing mail, but you could have a look at SOLVED - Account level filter "or" failing to see if it might be of any help.
 

vponteras

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

This seems to work for me

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
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

I'm glad to see you found a suitable filter rule. Thank you for sharing the outcome.
 

ragunathanc

Registered
Oct 25, 2019
1
0
1
India
cPanel Access Level
Root Administrator
Hi

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

This code works for single email id in to address.
if you combined with "our-domain.com", "allowed-domain1.com", "gmail.com","yahoo.com" means mails goes to all the email id's.
please share the solution. Thank you.