The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need a script to export list of all emails.

Discussion in 'E-mail Discussions' started by jetnet, Aug 20, 2006.

  1. jetnet

    jetnet Active Member

    Joined:
    Jun 30, 2004
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  2. jetnet

    jetnet Active Member

    Joined:
    Jun 30, 2004
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  3. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    This should get you started:

    find /home/*/etc/*/passwd

    The email addresses are the username (the first field)
     
  4. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    All forwarders are in /etc/valiases.
     
  5. ggriffit

    ggriffit Registered

    Joined:
    Feb 13, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  6. TheIdeaMan

    TheIdeaMan Member

    Joined:
    Apr 25, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
Loading...

Share This Page