getting list of email accounts from Whostmgr

cpaneldev

Registered
Jun 3, 2009
4
0
51
Hi,

I need to get a list of all email accounts, forwarders and mailing lists from a cpanel account using a perl script run under the WHM.

I know that the list of email accounts/forwarders and mailing lists can be retrieved using the api2 (i.e. Cpanel::Email::listpopswithdisk ) but that requires the script to be logged in as that cpanel user. How can I get that information in a WHM addon, i.e. the user is logged in as root on WHM.

thanks in advance.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
11
313
Houston, TX
cPanel Access Level
Root Administrator
Hi,

I need to get a list of all email accounts, forwarders and mailing lists from a cpanel account using a perl script run under the WHM.

I know that the list of email accounts/forwarders and mailing lists can be retrieved using the api2 (i.e. Cpanel::Email::listpopswithdisk ) but that requires the script to be logged in as that cpanel user. How can I get that information in a WHM addon, i.e. the user is logged in as root on WHM.

thanks in advance.
Actually, you can call that API2 function via the XML API and login as the root user to the XML API. This means you would only need to use the cPanel username (not their password) as a parameter to the XML API to fetch information about that cPanel account.

The XML API has a listaccts function you can call to gather a list of all the cPanel users you have on a server. You can build a script that loops through all those users to gather the information you need.
 

cpaneldev

Registered
Jun 3, 2009
4
0
51
Actually, you can call that API2 function via the XML API and login as the root user to the XML API. This means you would only need to use the cPanel username (not their password) as a parameter to the XML API to fetch information about that cPanel account.
could you provide a snippet that shows how to make the call from perl without the password and put the list of pop accounts into an array?

thanks.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
11
313
Houston, TX
cPanel Access Level
Root Administrator
could you provide a snippet that shows how to make the call from perl without the password and put the list of pop accounts into an array?

thanks.
I'll leave the Perl coding to you, but I'll help with our APIs. If you take the listpopswithdisk example we provide and replace port 2083 with 2087, and HTTP authenticate as the WHM user rather than a cPanel user, you've got the API code you need. Here's our listpopswithdisk example:

CallingAPIFunctions < AllDocumentation/AutomationIntegration < TWiki
 
Last edited:

cpaneldev

Registered
Jun 3, 2009
4
0
51
ah thanks, switching to port 2087 and getting the whm "hash" did the trick.

One more question: I get the list of accounts, but the password for each pop account is not part of the results. How can I get the password for each pop account as well?

thanks.
 

eeadmin

Well-Known Member
Oct 21, 2004
69
0
156
Dallas, TX
Exactly what I was looking for

Thanks this was exactly what I was looking for! We are trying to better integrate our customer info into other applications.
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
ah thanks, switching to port 2087 and getting the whm "hash" did the trick.

One more question: I get the list of accounts, but the password for each pop account is not part of the results. How can I get the password for each pop account as well?

thanks.
These are stored in one way encrypted hashes on your server, meaning that you cannot retrieve them, only change them.