Restrict outgoing email to certain domains

mrasmith

Member
May 28, 2010
6
0
51
Hi, I'm trying to restrict emails from my account (mydomain.com) and only allow users email addresses at mydomain.com and myotherdomain.com, with the exception of users john and david ..

I've tried the code below with no luck, all emails fail !?

I'm new to this and this is my first attempt so I apologise if I'm way off !

Any help would be appreciated, thanks.

Code:
if first_delivery
   and ("$h_from:" contains "@mydomain.com")
   and ("$h_from:" does not contain "[email protected]" or "$h_from:" does not contain "[email protected]")
   and ("$h_to:, $h_cc:" does not contain "@mydomain.com" or "$h_to:, $h_cc:" does not contain "@myotherdomain.com")
then
   fail "Cannot send to this recipient."
endif
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello,

Can you confirm if you are attempting to filter outgoing email (e.g. mail sent FROM the cPanel server), incoming email, or both? What method did you use to setup the filter?

Thank you.
 

mrasmith

Member
May 28, 2010
6
0
51
Hi, thanks for the reply.

I'm trying to restrict outgoing email to be limited to sending to certain domains.

I put the filter file above in /etc/cpanel_exim_customfilter and then pointed the 'system filter file' setting at this within the Exim Configuration Manager on WHM.

Is there an easier way to achieve this ?

Thanks again.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello,

A custom Exim system filter rule is the correct approach when attempting to block outgoing email. Here are some threads with examples you may want to use when developing and testing your own custom rules:

Blocking all cPanel users from emailing specific domains/email accounts
Need to filter ALL email

Also, 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.
 

mrasmith

Member
May 28, 2010
6
0
51
Yes I'm using a custom system filter file with my rules and have that file specified in the "System Filter File" option.

Thanks, I'll have a look at those threads.