Results 1 to 3 of 3

Thread: API to create/delete forwarder and aliases

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    1
    cPanel/WHM Access Level

    Root Administrator

    Question API to create/delete forwarder and aliases

    Hi!

    cpanel: 11.32.2 (build 25)
    exim: 4.77

    Ideally, I need to use PHP to programatically create aliases for a forwarded email address.

    What I have is dothis@domain.com piped to a php script... this works fine and now I want to create aliases for that email address programatically.

    Baring that, I want to create multiple forwarders for that same pipe to php script.

    I've downloaded both xml-php class and cpanel-public-phpapi class off of github and read through that, read the online docs and I see no mention anywhere of creating aliases or forwarders.

    Any help would be greatly appreciated!

    Thanks!

    Pete
    Last edited by ppetree; 05-30-2012 at 05:46 PM.

  2. #2
    Member
    Join Date
    Jul 2011
    Location
    Palmerston North, New Zealand
    Posts
    41
    cPanel/WHM Access Level

    Root Administrator

    Default Re: API to create/delete forwarder and aliases

    Using the XMLAPI you can call an API2 function to add an email forwarder.

    Email Module Documentation
    Regards
    Stefan Andres Charsley
    WebFront.co.nz

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    2
    cPanel/WHM Access Level

    Website Owner

    Default Re: API to create/delete forwarder and aliases

    Hi Pete,

    I came up with this solution to add a forwarder using the cPanel API that is piped to a script.

    Code:
    <?php
    include_once "../includes/class/XmlApi_cPanel.php" ; 
    $host 		= 'yourhost.com'; 
    $user 		= 'username';
    $password	= 'password'; 
    
    $xmlapi = new xmlapi($host, $user, $password); 
    $xmlapi->password_auth("username", "password"); 
    
    $xmlapi->set_port(2083);
    
    $xmlapi->set_debug(1); 
    
    
    $p['domain']    = 'yourhost.com'; 
    $p['email']     = 'beer';  
    $p['fwdopt']    = 'pipe'; 
    $p['pipefwd']   = '/home/'.$user.'/public_html/parsingScript.php'; 
    #$p['forwarder']	 = 'beer@yourhost.com=|/home/yourhost/public_html/parsingScript.php';
    
    $res = $xmlapi->api2_query($user, 'Email', 'addforward', $p); 
    #$res = $xmlapi->api1_query($user, 'Email', 'delforward', $p); 
    var_dump($res);  
    ?>
    The problem I have been having is the 'delforward' works nicely if you are deleting another email address but I haven't worked out how to delete items that work with the pipe method... You will note the port has been changed to the cPanal API as it defaults to the WHM one as I don't have access to a WHM as I'm not a reseller.

    That's my two cents anyway.

    Hope it's helpful
    Last edited by philipnewmannz; 06-03-2012 at 06:22 PM. Reason: Spelling Error

Similar Threads

  1. CLI api for adding aliases
    By assid in forum cPanel Developers
    Replies: 1
    Last Post: 05-24-2011, 08:14 AM
  2. Delete forwarder using api
    By lazzymonk in forum cPanel & WHM Discussions
    Replies: 6
    Last Post: 03-15-2008, 10:30 AM
  3. Can't delete forwarder?
    By doni49 in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 03-01-2007, 01:10 PM
  4. Delete forwarder using PHP
    By WoodyUK in forum cPanel & WHM Discussions
    Replies: 4
    Last Post: 01-12-2005, 03:33 AM
  5. How to create email aliases?
    By MrYogi in forum cPanel & WHM Discussions
    Replies: 8
    Last Post: 06-08-2004, 10:14 AM