SOLVED Accept mail from certain TLD's only block everything else

ampapa

Member
Mar 14, 2018
5
0
1
US
cPanel Access Level
Website Owner
Is it possible using CPanel to accept email from only the following TLD's (com|net|org|int|edu|gov|mil|coop|us) and reject everything else?

This seems like it should be relatively easy to do but I've searched the internet and the forums and am coming up blank with specific instruction on how to accomplish this feat...

Thanks for any information you can provide.

ampapa,
 

keat63

Well-Known Member
Nov 20, 2014
1,963
267
113
cPanel Access Level
Root Administrator
Pretty easy from a domain side using Global Filters.
Login in to the domain Cpanel, create a global filter based on 'from ... does not end with'
or 'from .......does not contain'
A little experimentation I'm sure you'll achieve what you want.

On a server level, it's probably a little more complex, but as a website owner, you won't have access at server level.

Global Email Filters - Version 76 Documentation - cPanel Documentation
 

ampapa

Member
Mar 14, 2018
5
0
1
US
cPanel Access Level
Website Owner
Appreciate the reply.

When creating a Global/User filter on the account I understand the accept 'from' concept but that creates a problem. The mail needs to follow one of the "Actions" listed below:

Email Filter Action Rules
Discard Message Deletes the message with no Failure message.
Redirect to Email Sends the email to another email address.
Fail with Message Deletes the email and sends a failure message..
Stop processing rules Does not run any filter rules.
Deliver to folder Sends the email to a specified folder.
Pipe to program Sends the email to a program or script on the server.

The only one that seems to apply is "Discard Message" but that would mean I would have to list each TLD "I DO NOT" want to accept mail from and that would be silly and not very useful.

What makes more sense is to accept mail from those TLD's I DO WANT mail from, that list is posted earlier, and none of these actions appear to allow the mail to further be tested it has to be directed to a certain mail box, again not useful.

I don't think a 'from' filter is going to work.

I need to filter TLD's and continue with mail processing, how do I do that?

ampapa,
 

keat63

Well-Known Member
Nov 20, 2014
1,963
267
113
cPanel Access Level
Root Administrator
If you create a filter "If from does not end with .com" - "Discard message", then anything coming from .biz would be discarded as it doesn't end with .com

something like the attached image ??
 

Attachments

ampapa

Member
Mar 14, 2018
5
0
1
US
cPanel Access Level
Website Owner
I get the following when testing the filter... it matched something and was deleted.

here is the test data:
Code:
To: [email protected]
From: [email protected]
Subject: test

This is a test message.



The Filter has matched the following condition(s): 
(((((($header_from: does not end .com or $header_from: does not end .net) or $header_from: does not end .org) or $header_from: does not end .int) or $header_from: does not end .edu) or $header_from: does not end .gov) or $header_from: does not end .mil) or $header_from: does not end .us
   ((((($header_from: does not end .com or $header_from: does not end .net) or $header_from: does not end .org) or $header_from: does not end .int) or $header_from: does not end .edu) or $header_from: does not end .gov) or $header_from: does not end .mil
   (((($header_from: does not end .com or $header_from: does not end .net) or $header_from: does not end .org) or $header_from: does not end .int) or $header_from: does not end .edu) or $header_from: does not end .gov
   ((($header_from: does not end .com or $header_from: does not end .net) or $header_from: does not end .org) or $header_from: does not end .int) or $header_from: does not end .edu
   (($header_from: does not end .com or $header_from: does not end .net) or $header_from: does not end .org) or $header_from: does not end .int
   ($header_from: does not end .com or $header_from: does not end .net) or $header_from: does not end .org
   $header_from: does not end .com or $header_from: does not end .net
   $header_from: does not end .net
The folowing regex appears to be working... thanks for your idea.

.*@.*\.(?!(.*\.)?(com|net|org|int|edu|gov|mil|coop|us))
 
Last edited by a moderator:

keat63

Well-Known Member
Nov 20, 2014
1,963
267
113
cPanel Access Level
Root Administrator
Now that it works, in the short term I would be tempted to deliver the unwanted ones to a specific folder instead of discard.
At least until you are happy that you didn't miss something important.
Typical that the most important email you ever needed would be dropped . o_O
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
The folowing regex appears to be working... thanks for your idea.

.*@.*\.(?!(.*\.)?(com|net|org|int|edu|gov|mil|coop|us))
Thanks for sharing the outcome! I've marked this thread as solved.