Add to Favourites Add to Favourites    Print this Article Print this Article

Listing all E-Mail accounts on a system

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.

Was this answer helpful?

Also Read