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

raininbrain07

Registered
Apr 13, 2012
3
0
51
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? . . .
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
11
313
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.
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
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.