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!

Copying the Account level filter over to Global filter

Discussion in 'E-mail Discussion' started by Srinath S M, May 2, 2018.

  1. Srinath S M

    Srinath S M Registered

    Joined:
    Aug 24, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Bangalore
    cPanel Access Level:
    Root Administrator
    Hello Everyone,

    I have a very big filter rule I have created under cPanel home >> Email filters option specifically for an email account say test@domain.com.

    I wish to copy that one filter rule over to cPanel home >> Global Email Filters option.

    I have tried the following:
    ~~~~~~~
    Copied the filter rule from: /home/username/etc/domain_name/email_username/filters
    ----
    #Filtername
    if
    $header_from: is
    .............
    ..............
    ..............
    ..............
    ..............
    ..............
    then
    save "/dev/null" 660
    endif


    Over to the file /etc/vfilters/domain_name
    ~~~~~~~

    It does not seem to be working. Please suggest me a solution for the same.
     
  2. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    2,721
    Likes Received:
    186
    Trophy Points:
    143
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hello,


    The syntax of the filters for global and user is the same, the following is an example from my test server:

    Code:
    [root@server ~]# cat /home/user/etc/example.com/mailuser/filter
    # Exim filter - auto-generated by cPanel.
    #
    # Do not manually edit this file; instead, use cPanel APIs to manipulate
    # email filters. MANUAL CHANGES TO THIS FILE WILL BE OVERWRITTEN.
    #
    
    headers charset "UTF-8"
    
    if not first_delivery and error_message then finish endif
    
    #example2.com
    if
     $header_from contains "example2.com"
    then
     save "/dev/null" 660
    endif
    
    Code:
    [root@server ~]# cat /etc/vfilters/example.com
    # Exim filter - auto-generated by cPanel.
    #
    # Do not manually edit this file; instead, use cPanel APIs to manipulate
    # email filters. MANUAL CHANGES TO THIS FILE WILL BE OVERWRITTEN.
    #
    
    if not first_delivery and error_message then finish endif
    
    #example2.com
    if
     $header_from: contains "example2.com"
    then
     save "/dev/null" 660
    endif
    What should be noted is that these files shouldn't be modified directly you should be using the API calls to make modifications to them if you need to make the modifications via CLI. You can find the Email filter functions in our documentation for example this one will list all email filters for an account:

    UAPI Functions - Email::list_filters - Developer Documentation - cPanel Documentation

    Otherwise, you can make your modifications using the UI. Can you confirm that you changes to /etc/vfilters/example.com are still present? If they are present how are you determining that the filter is not functioning?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Srinath S M

    Srinath S M Registered

    Joined:
    Aug 24, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Bangalore
    cPanel Access Level:
    Root Administrator
    Hello Lauren,

    Thank you for responding. I have around 150 email addresses to add as From address condition. I first started by adding the email addresses in the From-condition of the user level filter one by one whenever I receive a spam email from an email address.

    Now the filter became huge and there are around 150 from-addresses to be added as the condition in the filter. This makes the UI addition method, practically tedious. I have to sit and add the email address one by one into the new global email filter.

    So was looking for a solution to achieve the same by directly editing the backend files.

    I am not familiar with the API calls. Please help me by explaining how can I achieve this with an example.

    I have removed the filters I have copied, from the file /etc/vfilters/example.com. I first copied the filter rule from /home/username/etc/domain_name/email_username/filters
    to
    /etc/vfilters/example.com

    Then I checked the option Cpanel home >> Global email filters. I could not see the filter getting listed there.

    So I have created a dummy filter from Cpanel home >> Global email filters and replaced the dummy filter code with the filter code I copied from "/home/username/etc/domain_name/email_username/filters". This time the filter rule was getting listed in the Cpanel home >> Global email filters however, it was not listing the Filter conditions when I moved forward to edit the filter rule.

    Though, I used the Filter testing option in the Cpanel home >> Global email filters with the proper paramters and I got the result as "Normal Delivery will occur" instead moving the test email to /dev/null.

    Any help would be greatly appreciated. Thanks in advance.
     
  4. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    2,721
    Likes Received:
    186
    Trophy Points:
    143
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @Srinath S M

    I understand that could become overwhelming with that many addresses. What might be a solution for you as it can be done via CLI is utilizing the exim custom filter. This would implement server wide filtering. We have documentation on how this is done here:
    How to Customize the Exim System Filter File - cPanel Knowledge Base - cPanel Documentation

    To use the API to enable a filter you'd use UAPI Functions - Email::enable_filter - Developer Documentation - cPanel Documentation
     
    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