How to export all email addresses and forwarders created in cPanel

The commands mentioned below need to be run either from SSH or Terminal (in WHM).

To export all all forwarders, run the command below.

cat /etc/valiases/* > /home/forwarders.txt

This will create a list of forwarders and place them at /home/forwarders.txt. Now, we can open this file using vi or nano or email it to ourselves using the command below.

mail -s 'list of forwarders' you@yourdomain.com < /home/forwarders.txt

To clean up, you can now delete the file /home/forwarders.txt by using the command below

rm /home/forwarders.txt

Next, to export all email addresses created in cPanel, run the command below:

cat /etc/userdomains | sed "s/://g" | awk {'system("ls -1d /home/"$2"/mail/"$1"/* 2> /dev/null")'} | sed "s/\// /g" | awk {'print $5"@"$4'} > /home/emailaddresses.txt

This will create a list of all email addresses and place them at /home/emailaddresses.txt. Now, we can open this file using vi or nano or email it to ourselves using the command below.

mail -s 'list of email addresses' you@yourdomain.com < /home/emailaddresses.txt

You can now delete the file /home/emailaddresses.txt by using the command below

rm /home/emailaddresses.txt

Was this article helpful?
YesNo