The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating global email filter via command line

Discussion in 'cPanel Developers' started by domeneas, May 23, 2016.

Tags:
  1. domeneas

    domeneas Active Member

    Joined:
    Sep 20, 2013
    Messages:
    27
    Likes Received:
    1
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Hi,

    I am trying to create an email filter with UAPI via the command line. I use:

    uapi --user=myusername Email store_filter account=spampro1234@spamprotection.com filtername=TestFilter action=deliver dest=destination@email.com match=contains part=$header_from: val=from@email.com

    which should take any email from from@email.com that is sent to spampro1234@spamprotection.com and forward it to destination@email.com

    I get this output though:

    ---
    apiversion: 3
    func: store_filter
    module: Email
    result:
    data: ~
    errors:
    - No valid rules.
    messages: ~
    metadata: {}

    status: 0

    Can anyone see what I am doing wrong?

    Thank you.
     
    #1 domeneas, May 23, 2016
    Last edited: May 23, 2016
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    You must URI-encode values when using this UAPI function:

    Percent-encoding - Wikipedia, the free encyclopedia

    There are third-party conversion tools you can find on a search engine if necessary. In addition, you may want to use the API Shell option in cPanel when testing the function:

    API Shell for cPanel - Documentation - cPanel Documentation

    You must enable it as a feature on the feature list associated with the package assigned to the account, and ensure the cPanel account is a reseller in order to use this feature.

    Thank you.
     
  3. domeneas

    domeneas Active Member

    Joined:
    Sep 20, 2013
    Messages:
    27
    Likes Received:
    1
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Hi,

    I have tried encoding just the values, essentially just the @ in the emails and the $ and : in header_from, and everything, and some things, but I cannot make it work. Is there not an example of a properly formatted uapi call somewhere I can look at?

    It is not an option to make the accounts re sellers unfortunately.

    uapi --user=myusername Email store_filter account=spampro1234%40spamprotection.com filtername=TestFilter action=deliver dest=destination%40email.com match=contains part=%24header_from%3A val=from%40email.com

    EDIT: I actually made it work, I HAD TO add a 1 behind action, dest, part, match and val.

    I had to escape the header value like this: \$header_from:

    I could NOT URI encode the email addresses, I HAD TO use @ otherwise it just said it was an invalid email address.
     
    #3 domeneas, Jun 2, 2016
    Last edited: Jun 2, 2016
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page