One possible solution for all email accounts for an entire WHM installation
Here's a rather kludgy solution that works, but could certainly be improved.
/etc/valiases/* contains all the forwarding accounts.
/etc/vdomainaliases/* contains all the domain forwarders.
The tricky one is the actual accounts. They live in /etc/vmail/passwd.* files.
My method for retrieving all of the above was a combination of find and cat (run these in a directory you can save to):
Code:
find /etc/valiases/* -exec cat {}\; > valiases
find /etc/vdomainaliases/* -exec cat {}\; > vdomainaliases
find /etc/vmail/passwd.* -exec cat {}\; > vmail
The next thing I did was to parse the vmail message via TextWrangler (which uses grep) to output just the directories of each account:
1. Used the regex below to find all lines not containing account info (including trailing hard return); replaced them with nothing to remove them
Pulled out just the path where the e-mail for that inbox resides
Replaced the above with
\2 in the grep that comes with TextWranger
After running the above, I put that file back on the server and ran this (vmail being the original file name, and vmail_space being the output file name):
Code:
cat vmail | xargs du -sh > vmail_space
That gave me a file containing the same info as the original file plus current disk usage for each account.
That file could be parsed further to output e-mail addresses rather than path names, but that should help get you started.
Hope that's helpful to someone else trying to get a complete list of e-mail addresses out for a cPanel/WHM server.
The other option I was considering was using the cPanel API--which should also work, but take a bit more coding.