If you are using dovecot and postfix with a SQLite backend you can easily add a new user account with just a few steps. If you are using a different database such as MySQL, the following steps should be easily transferrable. We are assuming this is a new user account for an already configured and existing domain name on your mail server.

First we’ll need to generate a new password using SHA512-CRYPT encryption using the doveadm utility. The command below will prompt you to enter a password twice, and output a hashed value starting with {SHA512-CRYPT}. We’ll use the generated hash as the value for our password column in our INSERT statement later.

sudo doveadm pw -s SHA512-CRYPT

Next, we’ll open up the SQLite database configured by Dovecot using sqlite3 and insert a new record into the users table. Your table name and schema can vary.

sudo sqlite3 dovecotdb.sqlite

INSERT INTO users (id, email, password) VALUES (17, 'new@domain.com', '{SHA512-CRYPT}$6$...');

To finalize the setup of the new user we will restart the dovecot and postfix services and we should be all set.

sudo service dovecot restart
sudo service postfix restart

Resources