Anachon Posted February 26 Posted February 26 Hallo, ich steh vor der Herausforderung viele Emailadressen zu importieren bzw. neu anzulegen. Prinzipiell dachte ich, das über die API zu machen, vorzugsweise auf der CLI. Ist das eine gute Idee? Gibt es dazu eventuell ein Beispiel? beste Grüße
0 d00p Posted February 26 Posted February 26 da es keinen email-adressen importer via UI gibt bietet sich die API an ja Ein beispiel wäre: <?php // include FroxlorAPI helper class require __DIR__ . '/FroxlorAPI.php'; // create object of FroxlorAPI with URL, apikey and apisecret $fapi = new FroxlorAPI('http://127.0.0.1/api.php', 'your-api-key', 'your-api-secret'); // source data (loginname only required if called as admin/reseller) $email_addresses = [ ['email_part' => 'one', 'domain' => 'domain.tld', 'loginname' => 'web1'], ['email_part' => 'two', 'domain' => 'domain.tld', 'loginname' => 'web1'], ['email_part' => 'three', 'domain' => 'domain.tld', 'loginname' => 'web2'], ['email_part' => 'four', 'domain' => 'domain.tld', 'loginname' => 'web2'], // ... ]; // loop through data foreach ($email_addresses as $email_addr) { // send request $fapi->request('Emails.add', $email_addr); // check for error if ($fapi->getLastStatusCode() != 200) { echo "HTTP-STATUS: " . $fapi->getLastStatusCode() . PHP_EOL; echo "Description: " . $response['message'] . PHP_EOL; } } See also API documentation: https://docs.froxlor.org/latest/api-guide/commands/emails.html
0 d00p Posted February 26 Posted February 26 Das Ganze funktioniert auch via CLI (siehe https://docs.froxlor.org/latest/admin-guide/cli-scripts/#api-call) bin/froxlor-cli froxlor:api-call admin Emails.add '{"email_part": "one", "domain": "domain.tld", "loginname": "web1"}'
0 Anachon Posted February 26 Author Posted February 26 Kurze Frage: also Adresse anlegen, wird auch das Konto direkt angelegt?
0 d00p Posted February 26 Posted February 26 nein, Konto anlegen ist ein zweiter Schritt - man kann ja auch Adressen haben, ohne das diese ein Konto sind. Müsstest du einen zweiten API call machen: <?php // include FroxlorAPI helper class require __DIR__ . '/FroxlorAPI.php'; // create object of FroxlorAPI with URL, apikey and apisecret $fapi = new FroxlorAPI('http://127.0.0.1/api.php', 'your-api-key', 'your-api-secret'); // source data (loginname only required if called as admin/reseller) $email_addresses = [ ['email_part' => 'one', 'domain' => 'domain.tld', 'loginname' => 'web1', 'email_password' => 's3cret'], ['email_part' => 'two', 'domain' => 'domain.tld', 'loginname' => 'web1'], ['email_part' => 'three', 'domain' => 'domain.tld', 'loginname' => 'web2'], ['email_part' => 'four', 'domain' => 'domain.tld', 'loginname' => 'web2'], // ... ]; // loop through data foreach ($email_addresses as $email_addr) { // check for account-password $accnt_pwd = $email_addr['email_password'] ?? null; unset($email_addr['email_password']); // send request $fapi->request('Emails.add', $email_addr); // check for error if ($fapi->getLastStatusCode() != 200) { echo "HTTP-STATUS: " . $fapi->getLastStatusCode() . PHP_EOL; echo "Description: " . $response['message'] . PHP_EOL; continue; } // create account if password is set if (!empty($accnt_pwd)) { // send request $fapi->request('EmailAccounts.add', [ 'emailaddr' => $email_addr['email_part'] . '@' . $email_addr['domain'], 'loginname' => $email_addr['loginname'], 'email_password' => $accnt_pwd ]); // check for error if ($fapi->getLastStatusCode() != 200) { echo "HTTP-STATUS: " . $fapi->getLastStatusCode() . PHP_EOL; echo "Description: " . $response['message'] . PHP_EOL; } } }
Question
Anachon
Hallo,
ich steh vor der Herausforderung viele Emailadressen zu importieren bzw. neu anzulegen.
Prinzipiell dachte ich, das über die API zu machen, vorzugsweise auf der CLI.
Ist das eine gute Idee?
Gibt es dazu eventuell ein Beispiel?
beste Grüße
6 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now