Get Free Linux Server Security, Performance & Troubleshooting Tips

List all IMAP and POP email accounts on a cPanel server

List all IMAP and POP email accounts on a cPanel server
4.8 (95%) 4 votes

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:

angiep@domain1.com
john@domain1.com
billing@domain2.com
support@domain2.com
stuff@domain3.com
audrey@domain3.com

@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.




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 *