1

Topic: Bulk create users from txt or csv file

Hi there,

using the latest version of iRedmail, i tested a lot of features and it's great so far.

I've looked into https://docs.iredmail.org/sql.create.mail.user.html and it can be great to use command line to create users... but i'll need to create tons of it...

I don't know how i can else :

- duplicate the command for tons of users to write it all on a sql file, so i can import that single sql file into mariaDb
- Use a command to read username & password from a txt file, also to create the sql file.

I think it's kinda basic but i'm lacking knowledge in scripting.

Thanks!

Regards,

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Bulk create users from txt or csv file

You need some basic shell scripting like this:

while read line; do
    email="$(echo $line | awk '{print $1}')"
    password="$(echo $line | awk '{print $2}')"

    bash create_mail_user_SQL.sh ${email} ${password} >> new_users.sql
done < users.txt

Save it in a file, e.g. create.sh.

Store the username (email) and password in the text file "users.txt" like this:

user-1@domain.com secret-password
user-2@domain.com another-password

Put both "create.sh" and "users.txt" on same directory (iRedMail-0.9.9/tools/), then run the "create.sh" script:

bash create.sh

it will generate SQL file new_users.sql, review it before importing.

3

Re: Bulk create users from txt or csv file

Hey,

Thanks a ton!

I figure it out by searching, but thanks anyways that's super sweet!

Here is how i did it :

while IFS='' read -r line || [[ -n "$line" ]]; do
    bash create_mail_user_SQL.sh $line password >>test.sql
done < "$1"

Regards