How to restrict an email account from sending emails outside domain ?

May 30, 2017
11
1
3
Burlington ON
cPanel Access Level
Root Administrator
I am trying to create a filter where 1 email account is not permitted to send emails outside of its domain. I have tried following script but it has some loopholes.

if $sender_address is "[email protected]"
and ("$h_to:, $h_cc:, $h_bcc:" does not contain "@domain.com")
then
fail text "Sorry one or more of your email recipients is not allowed. Please contact your System Administrator."
finish
endif

Loophole is if i include any other email recipient in to, cc or bcc along with a user from domain.com then this filter fall apart and doesn't work.
Ex: my email message contains following users

to: [email protected]
cc: [email protected]; [email protected]

is there a workaround which i can try ?

Your help is much appreciated.
TIA
 
May 30, 2017
11
1
3
Burlington ON
cPanel Access Level
Root Administrator