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.

Need a script to export list of all emails Using XMLAPI.

Discussion in 'cPanel Developers' started by raininbrain07, Apr 19, 2012.

  1. raininbrain07

    raininbrain07 Registered

    Joined:
    Apr 13, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I have script and it is not showing any output not even error. . . whole page blank. .

    Script is given below. . .

    if any one can help me on script for listing out the e-mail accounts. . from cpanel

    PHP:
    <?php
    include('xmlapi.php');
    $ip '001.100.010.1';
    // instantiate client
    $xmlapi = new xmlapi('$ip');

    // set credentials, these will be your reseller creds
    $loginname "cpusername";
    $loginpasswd 'cppassword';
    $xmlapi->password_auth($loginname$loginpasswd);
    $xmlapi->set_port('2082');

    // put only my account listing into the $users array
            
    @$cpuser->name $loginname;
            
    $users[] = $cpuser;

    //go thru each account and get the pops
    foreach( $users as $user) {
            
    $pops $xmlapi->api2_query($user->name'Email''listpopswithdisk');

            foreach( 
    $pops->data as $pop) {
                    
    $popstomod[$user->name][] = array('email' => (string) $pop->user'domain' => (string) $pop->domain);
            
                    }
    }
    ?>


    let me know what shall i do? . . .
     
  2. thewebhosting

    thewebhosting Well-Known Member

    Joined:
    May 9, 2008
    Messages:
    1,201
    Likes Received:
    1
    Trophy Points:
    38
  3. raininbrain07

    raininbrain07 Registered

    Joined:
    Apr 13, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Not able to understand . . . .
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The following code segment seems a bit convoluted just to get the email accounts associated only with that reseller user (not any cPanel accounts associated with that reseller user), which it seems you're trying to do here:

    Code:
    // put only my account listing into the $users array 
            @$cpuser->name = $loginname; 
            $users[] = $cpuser; 
    
    //go thru each account and get the pops 
    foreach( $users as $user) { 
    If anything, I'd put an echo statement inside the foreach loop to make sure it is being executed and troubleshoot from there.
     
  5. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    If you're connecting with the reseller password, you need to execute the calls via WHM. Trying to execute them as cPanel API2 calls directly will not work. Here's some sample code (not tested):

    Code:
    <?php 
    include('xmlapi.php'); 
    $ip = '001.100.010.1'; 
    // instantiate client 
    $xmlapi = new xmlapi('$ip'); 
    
    // set credentials, these will be your reseller creds 
    $loginname = "cpusername"; 
    $loginpasswd = 'cppassword'; 
    $xmlapi->password_auth($loginname, $loginpasswd); 
    $xmlapi->set_port('2087'); 
    
    // put only my account listing into the $users array 
            @$cpuser->name = $loginname; 
            $users[] = $cpuser; 
    
    //go thru each account and get the pops 
    foreach( $users as $user) { 
            //connect via xml-api to use api2
            $response = xmlapi->xmlapi_query('cpanel', array( 'cpanel_xmlapi_user' => $user->name, 'cpanel_xmlapi_module' => 'Email', 'cpanel_xmlapi_func' => 'listpopswithdisk', 'cpanel_xmlapi_apiversion' => 2));
           print_r($response);
    } 
    ?>
    
    It should be noted that either the XML-API calls or the API2 calls will output structures that must be parsed to get the data you want. You should see the structure with the print_r function and can go from there.
     
Loading...

Share This Page