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!

SOLVED Delete Email Forwarding Account with xmlapi.php

Discussion in 'cPanel Developers' started by BillSm, Jun 1, 2018.

Tags:
  1. BillSm

    BillSm Member

    Joined:
    Jun 1, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    US
    cPanel Access Level:
    Website Owner
    Hi,

    I am using this code posted by baldarab, Mar 19, 2014 to create a forwarding account. It works great.

    But now I am trying to use the same code to delete a forwarding account, but can't find the correct syntax on the forums.

    Tried: delforward, dodelfwd (in place of addforward) but neither works.

    $result_forward = $xmlapi->api2_query($account, 'Email', 'addforward', array($email_domain, $email_user, 'fwd', $dest_email) );
    ?>

    Any ideas?



    <?php
    include 'xmlapi.php' ;

    $ip = 'nnn.nnn.nnn.nnn';
    $root_pass = 'pppppppp';
    $account = 'aaaaaa';
    $email_user = $_POST['Username'];
    $email_password = $_POST['EmailPassword'];
    $dest_email = $_POST['ParentEmail'];
    $email_domain = 'domain.com';
    $email_quota = '10';
    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2083);
    $xmlapi->password_auth($account,$root_pass);
    $xmlapi->set_output('xml');
    $result = $xmlapi->api1_query($account, 'Email', 'addpop', array($email_user, $email_password, $email_quota, $email_domain) );
    $result_forward = $xmlapi->api2_query($account, 'Email', 'addforward', array($email_domain, $email_user, 'fwd', $dest_email) );
    ?>​
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,423
    Likes Received:
    1,957
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. BillSm

    BillSm Member

    Joined:
    Jun 1, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    US
    cPanel Access Level:
    Website Owner
    Hi Michael, thanks for the reply.

    I looked at the link and modified the code to:

    $result_forward = $xmlapi->api2_query($account, 'Email', 'delforward', array(address => $address_to_delete, forwarder => $dest_email) );

    But the address is still not deleted. Error logged was:
    Failed to delete forwarder. Unable to locate the forwarder “&quot;&quot;” for account “” on domain “mydomain.com”.

    Also tried with expilicity entering the address and forwarder emails instead of using variables. Same error.
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,423
    Likes Received:
    1,957
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Are you sure the forwarder you attempted to delete exists under the associated cPanel account?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. BillSm

    BillSm Member

    Joined:
    Jun 1, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    US
    cPanel Access Level:
    Website Owner
    Yes, even did a test email and received at the forwarding address.
     

    Attached Files:

  6. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

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

    Try deleting the forwarder via the command line to test that it works well. EX:

    Code:
    cpapi2 --user=username Email delforward email=user%40example.com emaildest=fwdtome%40example.com
    
    This will help determine if the issue is with your custom script, or with the API function itself.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. BillSm

    BillSm Member

    Joined:
    Jun 1, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    US
    cPanel Access Level:
    Website Owner
    Looking at your command line code, I changed it from:

    $result_forward = $xmlapi->api2_query($account, 'Email', 'delforward', array(address => $address_to_delete, forwarder => $dest_email) );

    To:

    $result_forward = $xmlapi->api2_query($account, 'Email', 'delforward', array(email => $address_to_delete, emaildest => $dest_email) );

    And it deleted correctly.

    Thanks so much for your help!
     
    cPanelMichael likes this.
  8. BillSm

    BillSm Member

    Joined:
    Jun 1, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    US
    cPanel Access Level:
    Website Owner
    Is there a way to show the status of a process? Like if the deletion or creation was successful or failed? Other than in an error log so I can see the status in the browser and display it?
     
  9. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,423
    Likes Received:
    1,957
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Here are a couple of existing posts you may find helpful:

    Can I get an example of the API?
    XML API Fatal errors

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. BillSm

    BillSm Member

    Joined:
    Jun 1, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    US
    cPanel Access Level:
    Website Owner
    Thanks again!
     
    cPanelMichael likes this.
  11. veronicabend

    veronicabend Well-Known Member

    Joined:
    Feb 25, 2005
    Messages:
    63
    Likes Received:
    1
    Trophy Points:
    158
    If I want to delete a pipe forwarder, is emaildest parameter "|script/path" ?

    Thanks
     
  12. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,423
    Likes Received:
    1,957
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @veronicabend,

    The emaildest parameter should be the path of the script if the destination is a pipe to a program. It needs to be in quotes and encoded. For example, you'd use a command like this if the path was /home/username/public_html/test.php :

    Code:
    uapi --user=username Email delete_forwarder address=test5%40domain.com forwarder="%7c%2fhome%2fusername%2fpublic_html%2ftest.php"
    The list_forwarders UAPI function is useful if you want to see the specific uri_forward destination to use with the emaildest parameter when deleting a forwarder:

    Code:
    uapi --user=username Email list_forwarders domain=domain.com
    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