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.

List of All E-mail Accounts/Aliases?

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

  1. chardnet

    chardnet Registered

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

    _Brendan
     
  2. blainemotsinger

    blainemotsinger Registered

    Joined:
    Jul 4, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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
    #

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

Share This Page