How to add email accounts from command line

DirectAdmin offers a script that will create an email account for a specific domain from the command line. This can be useful if you want to add many users. The script path is:

/usr/local/directadmin/scripts/add_email.sh

Info on the script usage:

[root@web ~]# /usr/local/directadmin/scripts/add_email.sh
Usage:
   /usr/local/directadmin/scripts/add_email.sh <user> <domain> '<cryptedpass>' <plaintext> <quota>

Variables <user> <domain> '<cryptedpass>' and <plaintext> are MANDATORY.
If plaintext is set to 1, then it can be a raw password
Else, set plaintext to 0 to use the provided crypted pass.
quota, in bytes. Use 0 for unlimited (default is 0)

The domain must already exist under a DA account
[root@web ~]#

The command to use is:

/usr/local/directadmin/scripts/add_email.sh USER DOMAIN PASSWORD 1 QUOTA

The quota value must be set in bytes. If you prefer to set the quota in MB, use $((QUOTA_IN_MB*1024*1024)) in the command. For a 50MB quota, use $((50*1024*1024)).

For example, for creating the email account user1@testplothost.com with 50MB quota, and ‘password123‘, use:

cd /usr/local/directadmin/scripts/
sh add_email.sh user1 testplothost.com password123 1 $((50*1024*1024))

Leave a Reply