if anyone is interested in open source mail server solution iRedMail and use MySQL as backend should now use my small cli script. Script has limited functions but it's perfect for things like importing new domains or creating many email accounts.
Script is opensource and use some functions from original iredadmin web management. So you need iredadmin installed, which is default option.
iRedMail CLI Tool on Github
Some nice examples
Basic use
# Add new domains
email-manage.py -a -d test.com
Domain added
# Add email but with no existing domain
email-manage.py -a -m test@test.cc
ERROR: Not added, domain test.cc not exist
# Add new email
email-manage.py -a -m test@test.com
Generated new email account:
Username: test@test.com
Password: f5nBpZ6mLZ
Domain: test.com
Initial alias added
Change email password
# Change password on mailbox, let system to generate random
email-manage.py -w -m test@test.com
Email: test@test.com
Password: T4h7Ty9j6h
Password successfuly updated
# Change password on mailbox, pass new password using argument
email-manage.py -w -m test@test.com -p newpass123
Email: test@test.com
Password: newpass123
Password successfuly updated
Search in database
email-manage.py -l -d test
+----------+-------------+-----------+-----------+
| domain | description | transport | Backup MX |
+----------+-------------+-----------+-----------+
| test.com | None | dovecot | no |
+----------+-------------+-----------+-----------+
email-manage.py -l -s test.com
Domains
+----------+-------------+-----------+-----------+
| domain | description | transport | Backup MX |
+----------+-------------+-----------+-----------+
| test.com | None | dovecot | no |
+----------+-------------+-----------+-----------+
Mailboxes
+---------------+------+----------+--------+-------+
| username | name | domain | Active | quota |
+---------------+------+----------+--------+-------+
| test@test.com | | test.com | yes | 0 |
+---------------+------+----------+--------+-------+
Aliases
+---------------+---------------+------+----------+--------+
| address | goto | name | domain | Active |
+---------------+---------------+------+----------+--------+
| test@test.com | test@test.com | | test.com | yes |
+---------------+---------------+------+----------+--------+
Import domains and mailboxes
For example, we have 2 files
- one with mailboxes "emails-list.txt" (one email per line)
- one with domains "domains-list.txt" (one domain per line)
# First we must add domains
for domain in `cat domains-list.txt` ; do
email-manage.py -a -d $domain
done
# Now we can import emails
for email in `cat emails-list.txt` ; do
email-manage.py -a -m $email
done
Fantastic script. Do you have an updated version for iRedAdmin 0.4?
ReplyDeleteThanks ! Sorry not now. I'm working on it.
ReplyDeleteHello!
ReplyDeleteThank you for the very nice piece, but by adding a new user I always get this error:
Traceback (most recent call last):
File "/usr/local/sbin/email-manage.py", line 450, in
add_object(args.domain, args.mailbox)
File "/usr/local/sbin/email-manage.py", line 244, in add_object
password = iredutils.generate_password_for_sql_mail_account(random_string, pwscheme=pwscheme)
AttributeError: 'module' object has no attribute 'generate_password_for_sql_mail_account'
Can you tell me which version of iredmail-cli and iredadmin are you using ?
ReplyDeleteRobert, same error for the generate_password_for_sql_mail_account here. Using latest iredmail-cli from github and iredmail 0.4.1
ReplyDeleteThank you for that. I believe I fixed it few minutes ago. It's iredmail-cli release v0.9.0-2
ReplyDeleteHi,
ReplyDeletewhen I try to execute the free version, I always get the following error:
File "email-manage-free.py", line 7, in
from prettytable import from_db_cursor
ImportError: No module named prettytable
thanks!
Hi Florian,
ReplyDeleteit's becouse you need prettytable for python. Take a look if your linux distribution has something like python-prettytable, or you can obtain it via python-pip. For ubuntu try "apt-get install python-prettytable" or when you have python-pip installed you can do "pip install prettytable"
I was able to use your script to create individual email accounts. Now I would like to use it to import many mailboxes and assigned passwords. Can this be done?
ReplyDeleteWhat would the record layout for the emails-list.txt look like? Is it CSV with a header row? Can I include the email address, password, domain? If so what would the command line and text file look like? Thanks!
Hi, currently this cli utility hasn't any option how to handle some file with accounts, but it's good idea.
ReplyDeleteOnly way how to do it now is write some shell script which parse your file with domains and accounts and call this utility for every one of them. First you have to add domains and when you have domains created you can create your accounts.
Ok, I got it to work using awk. Just created 12k accounts with assigned passwords. Thanks!
ReplyDeleteHere is the code I used in case someone else needs it:
awk -F '{cmd="email-manage-free.py -a -m " $1 " >> output"; cmd2="email-manage-free.py -w -m " $1 "-p " $2 " >> output"; system(cmd); system(cmd2)}' emails-list.txt
The CSV input file contains email address and password.
great job ! Thanks for sharing :)
ReplyDelete