Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I manage a number of cPanel / WebHostManager servers. On one of these servers we need to do an audit of all the email accounts from all the cPanel accounts. This server has nearly 300 cPanel accounts, each with between 1 and 50 email accounts within it...

Is there any way to get a list of all email accounts across all cPanel accounts on a cPanel / WebHostManager server?

share|improve this question

closed as off-topic by masegaloeh, Flup, Hyppy, Nathan C, mdpc May 1 '15 at 20:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 3 down vote accepted

I rolled my own solution. I found that each cPanel user has a YAML file in ~username/.cpanel/email_accounts.yaml which contains information about all email accounts under that cPanel user's account. Using that I whipped up a short Ruby script:


require 'yaml'

puts "email,username,domain,usage,quota"

Dir.glob('/home/*/.cpanel/email_accounts.yaml') do |email_accounts_file|
  email_accounts = YAML.load_file(email_accounts_file)
  #puts email_accounts_file
  #puts email_accounts.inspect
  #puts "---------------------------"

  email_accounts.each do |domain,info|
    if info['accounts'] then
      #puts "domain: #{domain}"
      info['accounts'].each do |username,info|
        puts "#{username}@#{domain},#{username},#{domain},#{info['diskused']},#{info['diskquota']}"

The script should br run as root and loops through all directories under /home looking for .cpanel/email_accounts.yaml files. (If your users' home directories are not stored as /home/username then edit line 7) The script prints out CSV separated data of all email accounts, what domain name they belong to, and what their disk usage and quota is, as reported by the YAML file.

share|improve this answer

I created a program to obtain this information directly from the cPanel's APIs.

The program requests a list of all the accounts in the server, extracts the users from the list and issues a new request per user to Email::listpopssingle to obtain all email accounts from the user's account.

share|improve this answer
Awesome, that's great! I'll check that out later. Nice work! – Josh Jun 1 '14 at 23:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.