As of DirectAdmin 1.39.2, a new script will exist which allows for the adding of email accounts from the command line:
/usr/local/directadmin/scripts/add_email.sh
This guide will describe how to read in a csv file formatted like this:user1@domain.com,password1,500
fred@domain.com,password2,500
bob@domain.com,password3,500
joe@domain.com,password4,500
carl@domain.com,password5,500
gary@domain.com,password6,500
1) Ensure you've got the latest version of DA. Â Test that you have the script and it's ready to accept input, by typing:
cd /usr/local/directadmin/scripts/
./add_email.sh
2) Create a new script:
cd /root
nano csv.sh
#!/bin/sh
#sample line:
#user@domain.com,password,500
FILE=mailboxes.csv
#the quotas are stored in bytes. so the # in meg, x 1024 x 1024 gives us bytes.(1024x1024=1048576)
QUOTAMULTIPLIER=1048576
if [ ! -s $FILE ]; then
echo "Ensure ${FILE} exists";
exit 1;
fi
for line in `cat $FILE`; do
{
EMAIL=`echo "$line" | cut -d, -f1`
PASS=` echo "$line" | cut -d, -f2`
QUOTA=`echo "$line" | cut -d, -f3`
QUOTA=`perl -e "print $QUOTA * $QUOTAMULTIPLIER"`
USER=`echo "$EMAIL" | cut -d@ -f1`
DOMAIN=`echo "$EMAIL" | cut -d@ -f2`
/usr/local/directadmin/scripts/add_email.sh $USER $DOMAIN "$PASS" 1 $QUOTA
};
done;
exit 0;
3) Add your data into the file /root/mailboxes.csv, set the csv.sh script to 755, then run it:
chmod 755 csv.sh
./csv.sh
4) Confirm that the data has been added correctly by viewing the accounts in:
User Level -> Email Accounts
as well as testing the login to /squirrelmail.