1

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?

0

2 Answers 2

3

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.

2

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.

1
  • Awesome, that's great! I'll check that out later. Nice work!
    – Josh
    Jun 1, 2014 at 23:57

Not the answer you're looking for? Browse other questions tagged .