Add email accounts from a CSV file on the command line.

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

Top Level » Email

Add email accounts from a CSV file on the command line.Last Modified: Aug 15, 2011, 6:37 pm
As of DirectAdmin 1.39.2, a new script will exist which allows for the adding of email accounts from the command line:


This guide will describe how to read in a csv file formatted like this:,password1,500,password2,500,password3,500,password4,500,password5,500,password6,500

and have it automatically be added into the /etc/virtual/ file.  Note, it's assumed the numbers on the right (500) are in Megabytes, and password are plaintext (can be changed to use crypted password).  It's important that password do not contain any commas, since CSV requires that commas be used as the separators.  Also the DA User and domain should already be setup.  Add a test email account first to ensure all paths are set correctly.

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/

You may want to manually run the script once with a test account, to ensure the script is working, before adding things in mass.

2) Create a new script:

cd /root

and fill it with the following code:

#sample line:,password,500


#the quotas are stored in bytes. so the # in meg, x 1024 x 1024 gives us bytes.(1024x1024=1048576)

if [ ! -s $FILE ]; then
           echo "Ensure ${FILE} exists";
           exit 1;

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/ $USER $DOMAIN "$PASS" 1 $QUOTA

exit 0;

3) Add your data into the file /root/mailboxes.csv, set the script to 755, then run it:

chmod 755

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.

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