• Home
  • Photos
  • Work
  • Blog
  • Contact
  • Security
  • Links
  • Command Line Tool for iRedMail (MySQL backend only)

    2014 - 03.13

    Hi,

    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

    Tags: , , ,

    Loading Facebook Comments ...

    12 Responses to “Command Line Tool for iRedMail (MySQL backend only)”

    1. Sean G says:

      Fantastic script. Do you have an updated version for iRedAdmin 0.4?

    2. Hossein says:

      Hello!

      Thank 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’

    3. Bob says:

      Robert, same error for the generate_password_for_sql_mail_account here. Using latest iredmail-cli from github and iredmail 0.4.1

    4. Florian Traun says:

      Hi,

      when 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!

      • Robert Vojčík says:

        Hi Florian,

        it’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”

    5. 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?
      What 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!

      • Robert Vojčík says:

        Hi, currently this cli utility hasn’t any option how to handle some file with accounts, but it’s good idea.

        Only 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.

    6. Thomas Anderson says:

      Ok, I got it to work using awk. Just created 12k accounts with assigned passwords. Thanks!

      Here 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.

    Your Reply