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
Bulk email addition
- franonline
- Closed
- Thread is marked as Resolved.
-
-
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.
-
-
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
-
Give me a CSV sample for one or two entries and I'll code the script in 5 minutes, based on your sample.
-
-
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
-
-
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:
You'll get such output:
Shell-Script- root@jessie:~/test# php imscp_mail_from_csv.php test.csv
- The user1@domain.tld mail account has been successfully inserted into the i-MSCP database.
- ERROR: user2@nuxwin.tld mail account has been skipped: This script can only add mail accounts for domains which are already managed by i-MSCP.
- The user3@sub1.domain.tld mail account has been successfully inserted into the i-MSCP database.
- WARN: The user1@domain.tld mail account already exists in the i-MSCP database. Skipping.
- ERROR: user2@nuxwin.tld mail account has been skipped: This script can only add mail accounts for domains which are already managed by i-MSCP.
- WARN: The user3@sub1.domain.tld mail account already exists in the i-MSCP database. Skipping.
- Request has been successfully sent to i-MSCP daemon.
- 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
-
Script added in contrib directory. See https://github.com/i-MSCP/imsc…b/imscp_mail_from_csv.php
-
-