SQL: Create new mail user

Attention

This document is applicable to iRedMail-0.9.6 and later releases. If you're running iRedMail-0.9.5-1 or earlier releases, please check tutorial SQL: Bulk create new mail users instead.

iRedMail ships the shell script tools/create_mail_user_SQL.sh to help you create new mail user quickly.

Create a new mail user

Sample usage:

cd iRedMail-0.9.6/tools/
bash create_mail_user_SQL.sh user1@example.com 'plain_password'

It will print SQL commands used to create this new user, you can save it to a file, then login to SQL server as root user and import this file. for example:

# cd iRedMail-0.9.6/tools/
# bash create_mail_user_SQL.sh user1@example.com 'plain_password' > /tmp/user.sql

# mysql -uroot -p
sql> USE vmail;
sql> SOURCE /tmp/user.sql;
# cd iRedMail-0.9.6/tools/
# bash create_mail_user_SQL.sh user1@example.com 'plain_password' > /tmp/user.sql

# su - postgres
$ psql -d vmail
sql> \i /tmp/user.sql;

Don't forget to remove /tmp/user.sql.

Notes:

Create multiple mail users

With some shell scripting trick, it's easy to create many mail users. Just run the script multiple times, but append the output SQL commands to same file.

# Create first user. With '>' to create or truncate file `/tmp/users.sql`.
bash create_mail_user_SQL.sh user1@domain.com 'password' > /tmp/users.sql

# Append users. With '>>' to append to `/tmp/users.sql`.
bash create_mail_user_SQL.sh user2@domain.com 'password' >> /tmp/users.sql
bash create_mail_user_SQL.sh user3@domain.com 'password' >> /tmp/users.sql
bash create_mail_user_SQL.sh user4@domain.com 'password' >> /tmp/users.sql

Then import /tmp/users.sql once to create them all at the same time.

See Also