Need a script to export list of all emails.

jetnet

Active Member
Jun 30, 2004
28
0
151
So SPAM has been a constant pain in everyones side for the last... 10 years. We have a great solution in place, but only one problem. We need a full list of all the email addresses being hosted on our server right now. Well with close to 200 domains on each of our servers, its a daunting task to go from server to server listing out all of the email addresses. Not to mention, but tomorrow, someone mad add a new email, and they would be without protection.

So the question is, is there an easy why to locally list out all e-mail addresses?

If that is possiable, is there a way to list out all of the forwards and lists addresses?
 

jetnet

Active Member
Jun 30, 2004
28
0
151
Let me be more specific about this. I do not want someone to write the script for me, I need someone to tell me where I can find this information, or how I can get the list. I can do everything else.

Thanks for the hints.
 

ggriffit

Registered
Feb 13, 2007
3
0
151
Need More Help...

Hey All,

I am not a linux admin at all, therefore I need more help getting the email address list. Can someone that maybe already wrote the script post or send me a copy and I can modify it to work on our system? I am very familar with scripting on a Windows box, but not on a *nix system at all and I need a list of email addresses so that they can run thru out gateway servers before it reaches this CPanel box.

Thanks!
Grant Griffith
 

TheIdeaMan

Member
Apr 25, 2005
9
0
151
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
Code:
/etc/(.*)\s
Pulled out just the path where the e-mail for that inbox resides
Code:
(.*)::(.*):(.*)
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.