How to create custom mail filters
Author: admin admin Reference Number: AA-00309 Views: 18353 Created: 2013-04-11 12:33 Last Updated: 2025-08-12 11:28 0 Rating/ Voters

KB: Creating and Using Custom Mail Filters in cPanel

Email filters are a powerful tool in cPanel that allow you to automatically manage incoming emails based on a set of rules. By creating filters, you can save time, improve organization, and significantly reduce the amount of spam in your inbox. This article will guide you through the process of creating custom mail filters, providing a variety of examples for different use cases.


Understanding Filter Types

cPanel offers two types of filters:

  • User-Level Filters: These filters apply only to a specific email account. They're ideal for personal sorting, blocking, and management of a single inbox.

  • Global Filters: These filters apply to all email accounts on your cPanel account. They are perfect for enforcing rules across your entire domain, such as blocking a known spam domain from reaching anyone on your team.

For most individual needs, User-Level Filters are the best choice.


Step 1: Accessing the Mail Filter Interface

  1. Log in to your cPanel account.

  2. In the Email section, click on Email Filters.

  3. If you are creating a User-Level Filter, find the email address you want to filter in the list and click Manage Filters.

  4. If you are creating a Global Filter, click the Global Email Filters icon instead.

  5. On the next screen, click the Create a New Filter button.


Step 2: Defining Filter Rules and Actions

Creating a filter involves two main parts: the rules (the conditions an email must meet) and the actions (what happens to the email if it meets those conditions).

Naming Your Filter

First, give your filter a descriptive name in the Filter Name box. A good name helps you remember what the filter does later on, for example, "Block Junk Senders" or "Move Newsletters to Folder."

Setting the Rules

The rules section is where you define the criteria. You can set rules based on various parts of an email, such as:

  • From: The sender's email address.

  • Subject: The subject line of the message.

  • To: The recipient's email address.

  • Body: The main content of the message.

  • Any header: Any line in the email's header, which contains technical information like the sender's IP address.

  • Spam Status: Whether the email has been flagged as spam by SpamAssassin.

You can combine multiple rules to create complex filters. For example, a filter could be set to act only if the email is from a specific sender AND contains a certain word in the subject.

Choosing an Action

The action determines what happens to an email that matches your rules. Common actions include:

  • Discard Message: Deletes the email without sending a bounce-back message to the sender. This is a great way to block unwanted senders.

  • Redirect to Email: Forwards the message to another email address you specify.

  • Deliver to Folder: Moves the email to a specific folder in your mailbox. This is ideal for organization.

  • Fail With Message: Deletes the email and sends a customizable bounce-back message to the sender, letting them know the message was not delivered.

  • Stop Processing Rules: This is a crucial action. If a message matches a rule with this action, it will not be checked against any subsequent filters. You should use this for your most important filters to prevent conflicts.


Practical Examples of Custom Mail Filters

Here are several examples of how you can use mail filters to manage your inbox effectively.

1. Blocking a Specific Sender

This is the most common use of email filters. If you are receiving unwanted emails from a particular email address, you can create a filter to discard them automatically.

Rules:

  • From equals spam-sender@example.com

Actions:

  • Discard Message

2. Filtering Messages by Subject

You can filter emails that contain specific keywords in the subject line. This is great for organizing messages or blocking spam with a consistent subject line.

Example 1: Organizing Project Emails

  • Filter Name: Project X Emails

  • Rules: Subject contains [Project X]

  • Actions: Deliver to Folder /project-x

This filter will automatically move any email with [Project X] in the subject to a dedicated folder, keeping your inbox clean.

Example 2: Blocking Spam Keywords

  • Filter Name: Block Bad Subjects

  • Rules: Subject contains Viagra

  • Actions: Discard Message

3. Filtering by a Sender's Domain

Instead of blocking a single email address, you can block an entire domain to stop all emails from that source.

Rules:

  • From contains @spammer-domain.net

Actions:

  • Discard Message

This filter will block emails from info@spammer-domain.net, sales@spammer-domain.net, or any other address from that domain.

4. Handling Mail from Specific Mailing Lists

Many mailing lists include a unique ID in the email header. You can use this to route all messages from a list into a dedicated folder.

Rules:

  • Any header contains List-ID: marketing-list.example.com

Actions:

  • Deliver to Folder /marketing-list

5. Filtering Based on the Email Body

This is useful for catching specific keywords within the email's content, such as a product name or a certain phrase.

Rules:

  • Body contains bitcoin investment opportunity

Actions:

  • Discard Message

6. Redirecting Emails to Another Address

If you want to forward messages from a specific client or contact to a different email address, a filter can automate this process.

Rules:

  • From equals important-client@clientdomain.com

Actions:

  • Redirect to Email my-other-email@domain.com

7. Combining Multiple Rules (AND/OR)

You can use the AND and OR operators to create more powerful filters.

Example: Blocking a Sender with a Specific Subject

This filter will only act on emails if they are from a specific address AND contain a particular subject line.

  • Rules:

    • From contains spam-sender@example.com AND

    • Subject contains Urgent Payment

  • Actions:

    • Discard Message

Example: Filtering Multiple Senders to One Folder

This filter will move emails from either of two specific senders into a single "Team" folder.

  • Rules:

    • From equals member1@team.com OR

    • From equals member2@team.com

  • Actions:

    • Deliver to Folder /team


Order of Operations and Testing

  • Filter Order: Filters are processed in the order they appear in your list. If an email matches a filter higher up in the list, no subsequent filters will be processed unless the action is set to "Stop Processing Rules." You can drag and drop filters to reorder them and change their priority.

  • Testing: cPanel provides a tool to test your filters. In the main Email Filters menu, there is a Filter Test box where you can paste the content of a raw email to see how your filters would process it. This is a great way to ensure your rules are working as intended before they are applied to live emails.

Quick Jump Menu