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.
Step 1: Determine the IP Address
Section titled “Step 1: Determine the IP Address”- 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.
Step 2: Create the Filter
Section titled “Step 2: Create the Filter”-
Log in to cPanel.
-
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.
-
Click Create a New Filter.
-
Enter a Filter Name.
-
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.xxxwith the actual IP) -
Range of IPs (last octet 0–255):
^xxx\.xxx\.xxx\.[0-9]{1,3}$
-
-
-
Under Actions, choose what to do with matching messages:
- Discard message.
- Redirect to another address.
- Move to a folder.
- Flag as spam.
-
Click Create.
Step 3: Test the Regex
Section titled “Step 3: Test the Regex”- Visit https://regex101.com/ to test your expression before applying.
- Ensure the regex is not too broad, otherwise legitimate mail may be filtered.