Cpanel: Count and List all mailboxes

Did you ever wanted to see how many mailboxes do you serve in total ?

You can see per user listing mailboxes in cPanel, but all of them is a pain. No such feature. It’s easy enough:

find /home/*/etc -maxdepth 2 -mindepth 2 -name passwd -exec cat {} \; | wc -l

 

you can also try:

find /home*/*/etc -name passwd -exec cat {} \; | wc -l

 

Want to check a complete list of all emails ? That’s even better:

 

#!/bin/bash -

cat /dev/null > /root/mailaccounts.txt

CP_ACCOUNTS=`ls -1A /var/cpanel/users/`

for user in `echo -n $CP_ACCOUNTS`
do
/root/mailaccounts.txt
domain=`grep -i ^dns /var/cpanel/users/$user |cut -d= -f2`
for dom in `echo -n "$domain"`
do
PASSWD_FILE="/home/$user/etc/$dom/passwd"
if [ -f $PASSWD_FILE ] && [ -s $PASSWD_FILE ]
then
for mail in `cat $PASSWD_FILE| cut -d":" -f1`
do
echo "$mail@$dom" >> mailaccounts.txt
done
fi
done
done

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.