better software through user-centered design

This is a sort of weird post, but recently I ran into an issue where I needed to transfer a bucket of email addresses from one hosting account to another.  In this case I am using Siteground as my host, and I was switching from one basic hosting account to another.  With the ultra low-priced plan you get cPanel access but no SSH or migration tools whatsoever.  There is an email account and email forwarder import tool, but no export, only showing you your email account on the screen.  The combination of laziness and geekiness overwhelmed me so I used the Firebug command line and wrote a script to export the data I needed to be imported into Excel and then uploaded to cPanel.

UPDATE: Since WordPress does not support code formatting, I put these scripts both in a Gist: gist.github.com/zachariahtimothy/5455126

Code and steps taken to complete this task for Email Addresses:

  1. Login to cPanel on old account and click on “Email Accounts” under the Mail Section.
  2. Change the results per page to be the max.  In my case, this showed me all email account.
  3. Bring up Firebug command line and input the following code:
    var rows = $("#table_email_accts tr.dt_info_row"),
    returnString = "";
    rows.each(function(i, item){
    var tdList = [];
    $(item).find('td:eq(0)').each(function(s, subItem){
    tdList.push($(subItem).text());
    });
    returnString += tdList + "\n";
    });
    console.log(returnString);

    This code may need tweaking for your cPanel version, but you should now see a list of the email addresses you desire in the Firebug console.
  4. Create a new text document in the directory of your choosing.  Copy and paste the email addresses inro the file and save as a csv.
  5. Create a new Excel spreadsheet with 3 columns and add the labels “Address”, “Password”, and “Quota”.
  6. On the data tab choose “From Text” under Get External Data.  Select the text (csv) file you just created and open.
  7. This will import the email addresses into the first column so all that needs to be done is add the passwords and email quota.
  8. All that is left is to click the Import Addresses/Forwarders link, upload the spreadsheet and follow the on-screen instructions.

Code and steps taken to complete this task for Email Forwarders:

  1. Login to cPanel on old account and click on “Forwarders” under the Mail Section.
  2. Change the results per page to be the max.  In my case, this showed me all forwarders.
  3. Bring up Firebug command line and input the following code:
    var rows = $(“#mailtbl tbody tr”),
    returnString = “”;
    rows.each(function(i, item){
    var tdList = [];
    $(item).find(‘td.truncate’).each(function(s,subItem){
    tdList.push($(subItem).text());
    });
    returnString += tdList + “\n”;
    });
    console.log(returnString);
    This code may need tweaking for your cPanel version, but you should now see a list of the email forwarders you desire in the Firebug console.
  4. Create a new text document in the directory of your choosing.  Copy and paste the email addresses into the file and save as a csv.
  5. Create a new Excel spreadsheet with 2 columns and add the labels “From Address”, and “To Address”.
  6. On the data tab choose “From Text” under Get External Data.  Select the text (csv) file you just created and open.  Make sure you select Delimited and comma as the delimitation type.
  7. This will import the from address in the first column and to address in the second.
  8. All that is left is to click the Import Addresses/Forwarders link, upload the spreadsheet and follow the on-screen instructions.

That is it for migrating email addresses and forwarders over to new accounts.  It is not that complex, but maybe it will save you 20 minutes of your life someday.  Note that if your version of cPanel does not have jQuery installed, you can use FireQuery to inject it.

About these ads

Comments on: "How To Export Email List from cPanel with JavaScript" (8)

  1. That was awesome! Thanks! It worked like a charm and I exported all 280 email addresses in a matter of seconds.

  2. [...] I found this solution from The UX Dev Guy [...]

  3. THANK YOU!!!

  4. I love you. Thank you so much!

  5. Worked a charm, although it shoud be noted that there are some whacky ” and “ in the forwarder script that need to be fixed to run properly.

  6. James Jewell said:

    Much appreciated

  7. Thanks a lot Zach,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 92 other followers

%d bloggers like this: