Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

List of All E-mail Accounts/Aliases?

Discussion in 'E-mail Discussion' started by chardnet, Nov 4, 2008.

  1. chardnet

    chardnet Registered

    Jun 30, 2005
    Likes Received:
    Trophy Points:
    Is there a way in WHM/Cpanel to obtain a list of all valid e-mail accounts and aliases that the server has on it?

    We're attempting to integrate all users and domains on our servers with a hosted anti-spam solution and they can synchronize user lists in a number of ways.

    I have full root access, so I can do about anything, just need to be pointed in the right direction.

  2. blainemotsinger

    blainemotsinger Registered

    Jul 4, 2008
    Likes Received:
    Trophy Points:
    listing all pop accounts in their domains.

    There are a couple of ways that I have seen to do this.

    First, is a command to run from the shell. You may want to APPEND this command into a text file, if you have a lot of accounts on your server, and will run past the line limit in your ssh screen, ie putty, terminal, etc. Also note, there are no 'line breaks' in the command. Sorry, I tried to add the <code> brackets, but it wouldn't let me.

    cat /etc/userdomains | grep -v nobody | while read x; do export DOMAIN=`echo $x | awk -F : '{print $1}'`; export USER=`echo $x | awk '{print $2}'`; for y in `cat /home/$USER/etc/$DOMAIN/passwd | awk -F : '{print $1}'`; do echo $y\@$DOMAIN; done; done

    Second is a script.

    #!/bin/sh -

    # Get a list of domains and POP accounts in each on a cPanel maildir-based server

    while read line
    domain=$( echo $line | awk 'BEGIN{FS=": "}{print $1}')
    user=$( echo $line | awk 'BEGIN{FS=": "}{print $2}')
    if [[ -d /home/$user/mail/$domain ]]
    echo "----------------------"
    echo "$domain"
    echo "----------------------"
    for box in `ls /home/$user/mail/$domain | grep -vE "(^cur$|^new$|^tmp$)"`
    echo "$box@$domain"
    ((box_count += 1))
    echo; echo "Total for $domain: $box_count POP boxes"; echo
    ((total_count += $box_count))
    done < $FILE

    echo; echo "Total POP boxes: $total_count"; echo

    There are probably more ways to go about this process, but like I said, these are the ways I've seen so far.
    #2 blainemotsinger, Nov 8, 2008
    Last edited: Nov 8, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice