Bulk email addition

  • Hi, Is there any way to add multiple email accounts? I need to add 300 emails and I can't find a command line tool or a way to import a csv. Regards :thumbsup:

  • Hello ;


    There is not out-of-box way but because mail accounts are stored into the i-MSCP database, you could easily create a PHP script which could read your CSV file by looping over each entries and then, do the needed SQL query and send a request to the i-MSCP daemon at end.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • Thank you nuxwin. I'll do that, could you please guime some advice on the SQL query and the request to the i-MSCP daemon?


    Regards

  • @franonline


    Give me a CSV sample for one or two entries and I'll code the script in 5 minutes, based on your sample.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • Really? you're great. I only have the following in the csv:


    <email>, <password>
    <email2>, <password2>


    So I guess it would be fair simple...


    Regards

  • Ok, I'll code it soon ;)

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • @franonline


    Hello ;


    As promised, you can find below a PHP CLI script which will allow you to import your mail accounts into the i-MSCP database, using a csv file as source.


    Before running this script, you must be aware of the following:

    • This script has been tested against last github ( 1.2.x branch ) but it should work with the last released version.
    • The script performs some validation for mail addresses and passwords syntax as it is done by the i-MSCP frontEnd. Thus, the entries in your csv file must be valid. If it is not the case, the wrong entries will be skipped.
    • The script does only accept mail accounts for domains ( subdomain, domain aliases.... ) which are already managed by i-MSCP.


    How to process

    • Upload the script below on your i-MSCP server
    • Run the script as follow:


    Shell-Script
    1. # php imscp_mail_from_csv.php <PATH_TO_YOUR_CSV_FILE>


    You'll get such output:


    Shell-Script
    1. root@jessie:~/test# php imscp_mail_from_csv.php test.csv
    2. The [email protected] mail account has been successfully inserted into the i-MSCP database.
    3. ERROR: [email protected] mail account has been skipped: This script can only add mail accounts for domains which are already managed by i-MSCP.
    4. The [email protected] mail account has been successfully inserted into the i-MSCP database.
    5. WARN: The [email protected] mail account already exists in the i-MSCP database. Skipping.
    6. ERROR: [email protected] mail account has been skipped: This script can only add mail accounts for domains which are already managed by i-MSCP.
    7. WARN: The [email protected] mail account already exists in the i-MSCP database. Skipping.
    8. Request has been successfully sent to i-MSCP daemon.
    9. root@jessie:~/test#


    As you can see in the above output, the script will informs you for each mail account when something goes wrong.


    Enjoy ;)

    Files

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • Script added in contrib directory. See https://github.com/i-MSCP/imsc…b/imscp_mail_from_csv.php

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206