List all IMAP and POP email accounts on a cPanel server

This is a quick hack to list all IMAP and POP email accounts on a cPanel server, from all the existing domains. If you ever need to list all your mail boxes that are currently working with the IMAP or POP3 protocol, then run this scripts:

To get all your IMAP mailboxes

cat /var/log/maillog | zcat /var/log/maillog-* | grep DOMAIN.COM | grep -i "imap(" | awk -F':' '{print $4}' | sort | uniq | sort | awk -F'(' '{print $2}' | awk -F')' '{print $1}'

For POP3, run this script:

cat /var/log/maillog | zcat /var/log/maillog-* | grep DOMAIN.COM | grep -i "pop3(" | awk -F':' '{print $4}' | sort | uniq | sort | awk -F'(' '{print $2}' | awk -F')' '{print $1}'

In both cases, replace “DOMAIN.COM” with your real domain name.

Output should be similar to:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

@cPBenny also suggested this command to get the full list of all your email accounts on a cPanel server:

for i in $(find /var/cpanel/users -type f | egrep -o '[a-zA-Z0-9]+$' | grep -v system);do whmapi1 list_pops_for user=$i;done

That’s all, now you know how to get / list all IMAP and POP email accounts on a cPanel server.

About the Author: Martin Keler

2 Comments

  1. This might be a better way to list all email accounts on a server.

    for i in $(find /var/cpanel/users -type f | egrep -o ‘[a-zA-Z0-9]+$’ | grep -v system);do whmapi1 list_pops_for user=$i;done

Leave a Reply

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