Knowledge Base
Categories: ,

Custom Mail Account and User Level Filters


Account and user level filters control how your incoming email is handled, helping to ensure that you receive more mail and less spam. cPanel allows you to manage filters for each email account on your domain. This can be useful for discarding spam, redirecting mail or piping messages to a program.

Note: it is strongly recommended that you use multiple, simple filters instead of one long/complex filter. Exim can handle multiple small filters much more effectively than one long rule.

Adding an Account or User Level Filter

To create an account or user level filter:

  1. Log into cPanel.

  2. In the Mail section, click Account Level Filtering or User Level Filtering, 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 - 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

    • Spam Status - the status SpamAssassin has been conferred on the message; it begins with either "Yes" or "No."

    • Spam Bar - the content of the Spam Bar header that SpamAssassin has generated for this message, this header contains plus (+) signs to denote the likelihood that the message is spam; more plus signs means the message is more likely spam

    • Spam Score - the overall spam score assigned to the message by SpamAssassin, expressed in digits

  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

    The following options are only applicable when the Spam Score option is selected:

    • is above (#s only) - scores greater than the number you define will be subject to the action selected

    • is not above (#s only) - all scores equal to or less than the defined number will be subject to the action selected

    • is below (#s only) - all scores below the defined number will be subject to the action

    • is not below (#s only) - all scores greater than or equal to the specified number will be subject to the action

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

    For example:

    This rule will target any emails from the sender [email protected]. You can add and remove rules by clicking the +/- buttons.

  9. 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 - redirects the message to another email 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 and make sure your script is executable and has the appropriate hashbang (hashtag)

      • #!/usr/local/bin/php -q -- For PHP

      • #!/usr/bin/perl -- For Perl.

  10. Click Create to initialize the filter

Testing a Custom Filter

To test the filter you created:

  1. From cPanel, in the Mail section, click Account Level Filtering or User Level Filtering.

  2. For a user level filter, click Manage Filters next to the email address you'd like to test.

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

  4. When the test is run, the next screen should display the results.

    The next screen summarizes the actions taken by the filter. It is important to read over the data to ensure that the filter produces the desired result.

Did you find this article helpful?

* Your feedback is too short