Setting up Email Filtering in cPanel
Previously we looked at setting up email accounts in cpanel. cPanel provides inbuilt features to filter or manage incoming Emails based on the rules that we specify. We will discuss the rules in detail later in this tutorial. There are two types or levels of filtering available, account level filtering and user level filtering. The difference between these two options is that in account level filtering, filter rules are applicable for all the Email accounts under the domain (eg: firstname.lastname@example.org, email@example.com etc) and in user level filtering, filter rules are applicable for the selected Email account (eg: firstname.lastname@example.org).
Rules are the conditions that we specify to filter the Emails. The patterns or keywords specified in the rules will be checked against the incoming mail and if it matches the action specified in the rule will be taken.
Account level filters can be created from cPanel >> Mail >> Account Level Filtering
Click on ‘Create a New Filter‘ button to create a new filter.
As you can see in the above screenshot, there is a Filter Name box to specify the name of the filter. This name should be unique for each filter.
To create an Email filter add a Filter Name, set the Rules (Options and Operators) and specify the Actions to be taken if the rule is matched with the incoming mail.
Email Filter Rule Options (First drop down in the Rules)
From – To check the from email address of the incoming mail (Email address from which the mail is received).
Subject – To check the subject of the incoming mail.
To – To check the ‘To’ address of the incoming mail (Email address to which the mail is sent to).
Reply Address – To check the Email address to which the reply is sent.
Body – To check the content of the mail
Any Header – To check header of the mail.
Any Recipient – To check all recipients of the mail.
Has not been previously delivered – To check mails present in the mail queue which are not delivered yet.
Is an error message – To check error messages received from auto-responders.
Spam Status – To check the status that SpamAssassin assigned to the message.
Spam Bar – To check the content of the Spam Bar header that SpamAssassin has generated for this message.
Spam Score – To check the spam score assigned to the message by SpamAssassin
Email Filter Rule Operator (Second drop down in the Rules)
equals – This operator matches the exact string you define below.
matches regex – This operator matches the regular expression defined below.
Contains – This operator checks if the rule option contains the string which is defined.
does not contain – This operator checks if the rule option does not contain the string which is defined.
begins with – This operator checks if the rule option begins with the string you define.
ends with – This operator checks if the rule option ends with the string you define.
does not begin – This operator checks if the rule option does not begin with the string you define.
does not end with – This operator checks if the rule option does not end with the string you define.
does not match – This operator checks if the rule option is not equal to the string you define.
You can see a blank box below the two drop downs, this is where you need to enter the string to be matched.
Discard Message – To discard or delete the mail with no failure message.
Redirect to Email – To redirect the email to a different Email address.
Fail with Message – To delete the mail with an automatic failure message.
Stop processing rules – To not run any filter rules.
Deliver to folder – To move the mail to a specified folder.
Pipe to program – To send the mail to a specified program or script.
This option lets you test the custom rules. You can specify the ‘To‘ address, ‘From‘ address and ‘Subject’ of the mail and see if the rules are working as it is supposed to.
User level filters can be created from cPanel >> Mail >> User-Level Filtering
You can select the specific Email address for which the rules to be applied. Everything else is just the same.
If you have any doubts with adding Email filters, feel free to contact our support department.