Blog

Custom Email Filtering across cPanel Server

Published on: May 18, 2019 by Albert Reilly

Custom Email Filtering across cPanel Server

Scenario:

Using a custom filter with custom rules to discard emails considered spam across the whole server.

HOWTO

Exim uses a global file to set filters for all the accounts in a server, but they contain just some default rules. We can add new rules to this file and make filters to work across the server.

Filters are usually setup using cPanel>>Global Filters but this is used only for filtering mails to that particular account. The filters created via cPanel is saved in /etc/vfilters directory.

So we can use the Global Filter in cPanel to generate these rules and then add these to the global file so that the change is available across the server. Below I will explain in detail on how to do this.

Below I will explain how the rules for filtering were created.

1. Log into cPanel >> Global Filters
2. Create a Filter

Global Filters

3. test1 filter for attaining ‘Spam status -> begins with -> Yes -> Discard

Global Filters
4. test2 filter for attaining ‘Spam bar -> contains -> ++++++ -> Discard

Global Filters

Now the rules created for these filters in the file /etc/vfilters/example.com is fetched and it is as below.

# Exim filter # Auto Generated by cPanel.  Do not manually edit this file as your changes will be overwritten.  If you must edit this filter, edit the corresponding .yaml file as well. if not first_delivery and error_message then finish endif #test1 if  $h_X-Spam-Status: begins "Yes" then  save "/dev/null" 660 endif #test2 if  $h_X-Spam-Bar: contains "++++++" then  save "/dev/null" 660 endif

Now the above snippet for filtering mails is now made global across the server by adding it to the file /etc/cpanel_exim_system_filter which is the file that exim checks for filtering contents.

Goto WHM >> Exim Configuration Manager and click Filters

Now we can see the used default file as below.

Now we make a new custom file via backend for this so that the filters are preserved even after any updates.

We copy the default file to a new file to keep the existing settings as well and then add the custom rules to it.

cp -a  /etc/cpanel_exim_system_filter /etc/cpanel_exim_system_filter_custom

Now we add the above snippet to the newly created file ‘/etc/cpanel_exim_system_filter_custom

Then the Exim Configuration Manager setting is changed to use this new file as below.

Now the filter is made global across the server.

Hope you enjoyed ! (smile)

Category : cPanel, Email service

Albert Reilly

Albert Reilly

Albert likes to explore and learn new things. He is hardworking, enthusiastic and is getting expertise in Linux administration, Networking and Security areas. He understands client requirements and is able to act accordingly. He has been working for 2 years with us.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Get new updates

Categories

$0.000 items