Filtering or Blocking Specific Senders and Content

Filtering / Blocking Specific Senders and Content   Filtering / Blocking Specific Senders and Content

E-mail filters control how your incoming e-mail is handled, helping to ensure that you receive more mail and less spam. cPanel allows you to manage filters globally (i.e. filters that apply to all e-mail accounts) or for each e-mail account on your domain. This can be useful for discarding spam, re-directing mail or piping messages to a program.

NB. It is strongly recommended that you use multiple, simple filters instead of one long/complex filter. Mail filters can handle multiple small filters much more effectively than one long rule.

Adding a filter:

1. Log into cPanel.

2. In the Email section, click Global Email Filters or Email Filters according to your preference.

3. For a user level filter, click Manage Filters next to the email address for which you wish to add a filter.

4. Click Create a New Filter.

5. In the Filter Name field, enter a name for the filter.

6. In the first drop-down menu under Rules, select a message characteristic.

  • From - the address from which the message was sent
  • Subject - the subject line of the message
  • To - address to which the message was sent
  • Reply Address - address to which the reply will be sent
  • Body - body or content area of the message
  • Any Header - a header of the message
  • Any recipient - a recipient of the message
  • Has not been previously delivered - affects messages still in queue for delivery
  • is an error message - affects error messages received from an auto-response system


7. In the adjacent drop-down menu, select an operator.

  • equals - exactly matches the string you define
  • matches regex - matches a regular expression you define
  • contains - contains the string you define
  • does not contain - does not contain the string you define
  • begins with - begins with the string you define
  • ends with - ends with the string you define
  • does not begin - does not begin with the string you define
  • does not end with - does not end with the string you define
  • does not match - is not equal to the string you define


In the field below, enter the filter or characteristics you wish to use as the filter. (Regular expressions are accepted.)

For example:

mail filtering

This rule will target any emails from the sender spammer@example.com.

You can add and remove rules by clicking the +/- buttons.

In the Actions drop-down menu, select an action for the rule you created.

  • Discard message - destroys the incoming message with no failure notice
  • Redirect to email - re-directs the message to another e-mail address that you specify
  • Fail with message - discards the message and automatically returns a specified failure notice to the sender
  • Stop processing rules - skips all filter rules
  • Deliver to folder - deposits the message into a specified folder
  • Pipe to a program - sends the incoming message to a program you have specified


When piping to a program, you should enter a path relative to your home directory. If the script requires an interpreter, such as Perl or PHP, you should omit the /usr/bin/perl or /usr/local/bin/php portion.


Make sure your script is executable and has the appropriate hashbang:
#!/usr/local/bin/php -q -- For PHP
#!/usr/bin/perl -- For Perl.

Click Create to initialize the filter.

Testing a Custom Filter:

From cPanel, in the Email section, click Global Email Filters or Email Filters.

For a user level filter, click Manage Filters next to the e-mail address that you would like to test.

In the Filter Test text box, type a test e-mail message and click Test Filter (be sure to include the characters or words that you have set your filter to catch).

To: test@localhost (If you have selected the To: filter enter the e-mail you are filtering here)
From: test@localhost (If you have selected the From: filter enter the e-mail you are filtering here)
Subject: test (If you have selected the Subject: filter enter the subject you are filtering here)
Body, This is a test message. (If you have selected the Body: filter enter the body content you are filtering here.

When the test is run, the next screen should display the results. This screen summarises the actions taken by the filter. It is important to read over the data to ensure that the filter produces the desired result.

Please Note:

1.If you are filtering certain words, then you need to be very careful about which words you use. Certain shorter words can also form part of longer words. For example: the word "mat" is also part of the word "tomato" which means that if you block the word "mat" then you would also block any e-mail containing the word "tomato".

2. Blocking special characters such as ! and $ is not recommended.

  • e-mail, spam, support
  • 1 Users Found This Useful
Was this answer helpful?