Import mail users from another system

  • Hi,

    I would like to import a large number of email accounts ("normal" and "forward") into i-MSCP. The customer and domain already exist in i-MSCP.

    I've read gui/public/client/mail_add.php to get an idea how email accounts are added by the GUI, and for me it looks that it is not a problem to manually add new records to the mail_users database table with the 'toadd' status.

    However, I am not exactly sure if I fully understand what the EventsManager does, and if I can trigger its function manually.

    1. EventsManager::getInstance()->dispatch(Events::onBeforeAddMail, [
    2. 'mailUsername' => $username,
    3. 'MailAddress' => $mailAddr
    4. ]);

    1. EventsManager::getInstance()->dispatch(Events::onAfterAddMail, [
    2. 'mailUsername' => $username,
    3. 'mailAddress' => $mailAddr,
    4. 'mailId' => $db->insertId()
    5. ]);
    6. send_request();

    Could anyone give me a short hint if this is possible at all, how this is best done, or where I can find some more info on the EventsManager?

    (Im running the latest version (1.5.3) of i-MSCP on Debian 9).

    Thank you,


  • To concretize my question: Is it possible to just add users to the DB with status "toadd" and then run some script (i.e., imscp-reconfigure) to generate the contents of /etc/postfix/imscp and all other stuff?

  • Ok, I used curl to send POST requests to i-MSCP, which did the job. Afterwards, I had to update the passwords in the database, as I only had password hashes available.

    Here is an example for adding a regular email account, just in case anyone needs to do something similar. Get username and domain from your data, and session id from your browser.

    1. curl -d "account_type=1&domain_name=${DOMAIN}&forward_list=&password=5vIHXnBc7Hm7&password_rep=5vIHXnBc70m7&quota=10&Submit=Add&username=${user}" \
    2. --cookie "iMSCP_Session=xxxxxx" \
    3. -H "Content-Type: application/x-www-form-urlencoded" \
    4. -X POST https://your.imscp.tld:8443/client/mail_add.php

    Afterwards update passwords

    1. UPDATE mail_users SET mail_pass = '${pass}' WHERE mail_addr = '${user}@${DOMAIN}';

    Prefix password with the password hash type, if not using the default (i.e., {CRAM-MD5}).

    Request to close issue.