Looking for cpanel api to grab email address from whm with php


Jun 24, 2006
We are working on a new billing system, and want to use a php api to connect to whm and grab the email address for a specific domain.

Anyone done this before?


Oct 21, 2008
Re: "Looking for cpanel api to grab email address from whm with php"

Although I am not aware of cPanel API for this purpose but in case if you fail to find required API, there is a manual way to retrieve this information using PHP script.

I don't really think cPanel/WHM stores actual email account names in file(s) on the server. You may have to parse couple of files and retrieve directory contents in order to accomplish it. If you are interested in doing it then here is what want to fetch from files/directories.

Each email account exists in the form of a directory under '/home/USER/mail/DOMAIN.TLD/' in the form '/home/USER/mail/DOMAIN.TLD/EMAIL'. Let us parse this path one by one.

=> The 'USER' is actual cPanel account's Username. If your script doesn't know about the User of a particular domain then it can be retreived from '/etc/userdomains' file. Each line of this file is of format "domain.TLD: user"

=> The 'DOMAIN.COM' is actual domain name whose email accounts you want to retrieve

=> The 'EMAIL' is in fact the prefix, the part that appears before the '@' sign. Suppose if you have an email account of the name '[email protected]' then the EMAIL refers to 'jbillu'.

To summarize, suppose there is a domain 'domain.com' with cPanel Username 'user' and email account 'jbillu' then the path will be '/home/user/mail/domain.com/jbillu'. Hope this will help.
Last edited: