Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Exclude Email Account from System Filter Rule

Discussion in 'E-mail Discussion' started by vponteras, Mar 9, 2018.

Tags:
  1. vponteras

    vponteras Member

    Joined:
    May 16, 2017
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Philippines
    cPanel Access Level:
    Root Administrator
    Hi All,

    I have a system filter rule in /etc/cpanel_exim_system_filter_custom and it is currently working now.

    Code:
    if (
      $h_to: does not contain "our-domain.com" and
      $h_to: does not contain "allowed-domain1.com" and
      $h_to: does not contain "allowed-domain2.com" and
      $h_to: does not contain "allowed-domain3.com" and
      $h_to: does not contain "allowed-domain4.com"
      )
      and
      ($h_from: contains "our-domain.com")
    then
      fail text "Unauthorized Mail"
    endif
    
    Now, I want an email account that will get excluded from that filter rule. For example all email account from @our-domain.com cannot send mails except for those domains our-domain.com, allowed-domain1.com, allowed-domain2.com, allowed-domain3.com and allowed-domain4.com but I want the email account excluded@out-domain.com excluded on that filter rule and can send to all domains.

    Please help :(
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    You could try adding a separate filter rule ahead of the existing one that allows the message to proceed if it matches the specific condition you want to whitelist. Use the "Stop Processing Rules" action on the new filter rule so that the additional filter rules are not processed. Here's a document you may find helpful:

    How to Configure Mail Filters - cPanel Knowledge Base - cPanel Documentation

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. vponteras

    vponteras Member

    Joined:
    May 16, 2017
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Philippines
    cPanel Access Level:
    Root Administrator
    How do I position the filter rule? Is it before the fail rule or after it? Will this do?

    Code:
    # Block all except for listed domains
    if (
      $h_to: does not contain "our-domain.com" and
      $h_to: does not contain "allowed-domain1.com" and
      $h_to: does not contain "allowed-domain2.com" and
      $h_to: does not contain "allowed-domain3.com" and
      $h_to: does not contain "allowed-domain4.com"
      )
      and
      ($h_from: contains "our-domain.com")
    then
      fail text "Unauthorized Mail"
    endif
    
    # Exclude email account from block all rule
    if ($h_from: contains "excluded@our-domain.com")
      and
      ($h_to: contains "@")
    then
      finish
    endif
    
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    You'd actually want to add the new rule before the existing rule. Here's an example of how it should look:

    Code:
    #123
    if
     $header_from: matches "excluded@our-domain.com"
    then
     finish
    endif
    
    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. vponteras

    vponteras Member

    Joined:
    May 16, 2017
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Philippines
    cPanel Access Level:
    Root Administrator
    Hi Michael, will this do?

    Code:
    if
      ($h_from: matches "excluded@our-domain.com")
    then
      finish
        elif
          (
            $h_to: does not contain "our-domain.com" and
            $h_to: does not contain "allowed-domain1.com" and
            $h_to: does not contain "allowed-domain2.com" and
            $h_to: does not contain "allowed-domain3.com" and
            $h_to: does not contain "allowed-domain4.com"
           )
          and
           ($h_from: contains "our-domain.com")
        then
          fail text "Unauthorized Mail"
        endif
    endif
    
     
  6. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    That looks like a single rule. You should try setting up multiple rules first, like you started in your previous example.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice