SOLVED Exim Custom Filter for outbound messages

BassTeQ

Well-Known Member
Aug 31, 2008
67
8
58
Hi,

I'm trying to create a custom exim filter that will reject outgoing emails with specific text in the subject line.
I've created a new filter /usr/local/cpanel/etc/exim/sysfilter/options/server_custom_filter

Code:
if ("$h_subject:" contains "Custom Text")
then
  fail text "Email subject blocked by keyword"
  seen finish
endif
And restart exim, but it's not blocking the outound emails.

Do I need to rebuild /etc/cpanel_exim_system_filter, If so how? I don't see any refrence to my new rule in there .

Here's the settings in WHM.
1668036094976.png
Thanks
 
Last edited:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,163
2,410
363
cPanel Access Level
Root Administrator
Hey there! That all looks correct, and you don't need to restart or rebuild anything else. Do you see anything helpful when you check the Exim logs at /var/log/exim_mainlog while sending a message that would trigger that filter?
 

BassTeQ

Well-Known Member
Aug 31, 2008
67
8
58
Thanks, here's the log.

Code:
2022-11-22 17:07:27 SMTP connection from [X.X.X.X]:64686 (TCP/IP connection count = 1)
2022-11-22 17:07:30 1oxMRN-000BnD-QB <= [email protected] H=(SURFACEPRO8) [X.X.X.X]:64686 P=esmtpsa X=TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256 CV=no A=dovecot_login:[email protected] S=2589 [email protected] T="Custom Text" for [email protected]
2022-11-22 17:07:30 cwd=/var/spool/exim 3 args: /usr/sbin/exim -Mc 1oxMRN-000BnD-QB
2022-11-22 17:07:30 1oxMRN-000BnD-QB => removed <[email protected]> R=virtual_user T=dovecot_virtual_delivery C="250 2.0.0 <[email protected]> kiX5FiJnfGMdsQAAvxTo3g Saved"
2022-11-22 17:07:30 1oxMRN-000BnD-QB Completed
2022-11-22 17:07:33 SMTP connection from (SURFACEPRO8) [X.X.X.X]:64686 closed by QUIT
 

ServerHealers

Well-Known Member
Sep 21, 2015
100
57
78
India
cPanel Access Level
Root Administrator
BassTeQ

Yes, you should rebuild the Exim configuration and restart the service to include the custom filter on the Exim service there. If you check /etc/cpanel_exim_system_filter after rebuilding the Exim command, you will see that it is listed correctly there and reflect after the Exim service restart.
 

BassTeQ

Well-Known Member
Aug 31, 2008
67
8
58
Thanks all, I've run the commands and the filters are now working!
Support team also helped to provide me details on how to test a filter from the command line, which is useful!

Code:
exim -d-all+filter -bF /usr/local/cpanel/etc/exim/sysfilter/options/server_custom_filter < /root/test_email_from_file