Skip to content

Filtering incoming e-mail messages by IP address

Sometimes you may want to block or redirect messages coming from specific IP addresses. cPanel’s Email Filters feature allows you to create rules that process incoming mail based on the sender’s IP.

  • Every e‑mail contains headers that show its origin.
  • Look for the Received: header in the raw message.
  • Identify the IP address you want to filter.
  • For instructions on viewing headers, check your mail client’s documentation.
  1. Log in to cPanel.

  2. On the Tools page → Email section, choose one of the following:

    • Email Filters → create a filter for a specific account.
    • Global Email Filters → create a filter for all accounts under the domain.
  3. Click Create a New Filter.

  4. Enter a Filter Name.

  5. Under Rules:

    • First box → Any header.

    • Second box → matches regex.

    • Third box → enter a regular expression for the IP:

      • Single IP:

        ^xxx\.xxx\.xxx\.xxx$

        (replace xxx.xxx.xxx.xxx with the actual IP)

      • Range of IPs (last octet 0–255):

        ^xxx\.xxx\.xxx\.[0-9]{1,3}$
  6. Under Actions, choose what to do with matching messages:

    • Discard message.
    • Redirect to another address.
    • Move to a folder.
    • Flag as spam.
  7. Click Create.

  • Visit https://regex101.com/ to test your expression before applying.
  • Ensure the regex is not too broad, otherwise legitimate mail may be filtered.