Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 1 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:

#!/usr/bin/ruby

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']}"
      end
    end
  end
end

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 at 23:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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