List of all hosted email addresses

John Schmerold

Well-Known Member
Apr 21, 2004
81
6
158
st. louis
cPanel Access Level
Root Administrator
This four liner produces a list of your email addresses, it is helpful if you are using an external spam filter

#!/bin/bash

find /etc/valiases/* -type f | xargs -ifile sed -e 's/:.*//' file > /usr/src/getAllEmail.txt

ls -d /home/*/mail/*/*/ | awk 'BEGIN { ; } ; { ; tcmd = "test -d " $1 ; if(!system(tcmd)){ ; split($1,MyArray,"/") ; print MyArray[6] "@" MyArray[5] ; } ; }' >> /usr/src/getAllEmail.txt

sed -i -e 's/*.*//' /usr/src/getAllEmail.txt
sed -i '/^\s*$/d' /usr/src/getAllEmail.txt

Hope this helps someone.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
Hello :)

Thank you for sharing this script. Please note that user-submitted scripts are not tested or supported by cPanel. We encourage everyone to review all aspects of this script before using it on a production server.

Thank you.