Listing all E-Mail accounts on a system


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » Email

Listing all E-Mail accounts on a systemLast Modified: Aug 30, 2012, 2:13 am
If you need to get a full list of all created end-User E-Mail Accounts, you can use a script to do so:

#!/bin/sh
cd /etc/virtual
for i in `cat domains`; do
{
   if [ ! -s $i/passwd ]; then
       continue;
   fi

   for u in `cat $i/passwd | cut -d: -f1`; do
   {
       echo "$u@$i";
   };
   done;

};
done;
exit 0;

Which will show you all email accounts that were created by Users on this system.
This does not include system accounts.

The same idea, with a few changes, can be used to break it down on a per-Reseller basis:

#!/bin/sh
USERS=/usr/local/directadmin/data/users
VIRTUAL=/etc/virtual
for ul in `ls ${USERS}/*/users.list`; do
{
   r=`echo $ul | cut -d/ -f7`
   echo "";
   echo "Email Accounts for Reseller $r";

   for u in `cat $ul; echo $r`; do
   {
        for d in `cat ${USERS}/$u/domains.list`; do
        {
             if [ ! -s ${VIRTUAL}/$d/passwd ]; then
                  continue;
             fi
             
             for e in `cat ${VIRTUAL}/$d/passwd | cut -d: -f1`; do
             {
                  echo "$e@$d";
             };
             done;
        };
        done;
   };
   done;
};
done;
exit 0;

Don't forget to chmod the script to 755.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST