Came across with something interesting and felt like sharing it..
I was doing this networking website for one of my client and one of the requirement was that whenever a new user registers on the website, his/her email id firstname.lastname@example.org should be created automatically.
I started R&D if that’s possible in the first place. Google is my friend and i came across with cpanel api.
cpanel is a linux hosting application and thus wont support .net, so its not for .net developers. I am yet to find something equivalent on any windows hosting application
What is it
If you have a hosting account which has cpanel interface (most of the linux hosting providers have cpanel only i guess), you can write your own php code to access your hosting service and perform actions like adding/deleting email accounts, ftp accounts, adding sub-domains etc..
Through the hard-to-navigate-through documentation i found my way to xmlapi class which provides helper functions to make things easier for you. You can download the xmlapi class along with examples from github
The examples provided with the download uses WHM root user’s credentials (lets not go into details, coz i have no clue at all 🙂 ). I’ll take my example, i have a linux hosting account(not reseller) and i have cpanel access, obviously i have limited autorization to perform actions on the server, i dont have administrative priviledges equal to the root user of the server. So i had to change few things to suit my needs.
An example code to create email accounts on your server would be:
include_once "xmlapi.php" ;/*the file donwloaded from github*/
$ip = 'your.servers.ip.address';
$root_pass = 'your_cpanels_login_password';
$account = "your_cpanels_login_name";
$email_user = "wdw";
$email_password = "pass123";
$email_domain = "your_domain.com";/*this will create 'wdw@your_domain.com'*/
$email_quota = '10';
$xmlapi = new xmlapi($ip);
$xmlapi->set_port(2083);/* the ssl port for cpanel */
print $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
So if your login creadentials are correct the above code will create wdw@your_domain.com which you can see listed under all email accounts when you login to your cpanel.
So yea.. that’s it.. I found it pretty cool, can definitely think of using the api in many ways.