This guide is not aimed at being a complete how-to on modifying the Exim System filter as there are various rules that can be written and modified. In this example, we'll focus on preventing specific users from sending to specific providers such as Google, or Yahoo. By editing your Exim System filter at /etc/cpanel_exim_system_filter, we can add and remove rules to help you filter the mail as you desire.
- Start by logging into the cPanel server via SSH.
- Next, copy the system filer to a new file. You can name this anything you would like.
cp /etc/cpanel_exim_system_filter to /etc/cpanel_exim_system_filter_custom
- Using your favorite editor, vi/vim/nano modify /etc/cpanel_exim_system_filter_custom and use the following as a template.
#Custom exim block for specific users $date
if $header_from: contains "firstname.lastname@example.org" or $header_from: contains "email@example.com" and
$header_to: contains "@gmail.com" or $header_to: contains "@outlook.com" or $header_to: contains "@hotmail.com" or $header_to: contains "@yahoo.com"
fail text "This message is not able to be sent to the destiation due to your hosts configuration. Please speak with your server admintrator"
- Once completed, log in to your WHM and navigate to Home » Service Configuration » Exim Configuration Manage » Filters Tab.
- Replace the system filter with your custom filter that we modified from earlier.
- Click on Save
To verify this is working, log in to your webmail, or email client and try sending an email to one of the blocked domains. You should receive a bounce with the message "This message is not able to be sent to the destination due to your server configuration. Please speak with your server administrator"
You can also use the following to verify it was filtered through the exim mainlog.
exigrep " cancelled by system filter:" /var/log/exim_mainlog