Email creation via Remote API scripting

Discussion in 'Installation/Configuration' started by jnewman67, Mar 23, 2021.

  1. jnewman67

    jnewman67 Active Member HowtoForge Supporter

    I'm just going to post a few findings here about using API scripts to create 300+ emails for a migration from a non-supported control panel - just in case someone else isn't sure what they were doing like me :)

    CentOS 8 Stream server, fresh install, only 1 client/site/domain set up, still in testing phase.

    I customized the ispc-import-csv-email.php script to be able to create both forwarders and mailboxes within the same script. i added a couple extra columns (type, forward_to) to the CSV data, then duplicated the "creation" portion of the script to do either mail_forward_add or mail_user_add based on the type (record['type']).

    but my biggest issue was getting the script to access the remote/json.php web portal via :8080

    i had defined the remote_URL as "https://192.168.0.102:8080/remote/json.php" but as the certificate for the server is self-signed, PHP was complaining without actually complaining - i was getting the message "Could not get mail_policy_get result".

    testing the remote_URL with WGET, i got a "certificate is not trusted" error. changing from HTTPS -> HTTP gave a "400 Bad Request" error.

    i finally had to redefine the remote_URL using an actual domain name that was defined in ISPConfig AND had an SSL certificate installed for that specific domain. setting the remote_URL to "https://server.mydomain.tld:8080/remote/json.php" then worked.

    now there are other errors, but i think those are CSV formatting issues - at least I'm getting data-related errors now!
     
  2. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    And alternative to using valid certificate (which is probably better, but...) is to use curl options to not require a valid certificate, eg. try uncommenting line 46.

    FWIW, when migrating a system recently we opted for all mail_users rather than any mail_forwarding entries, as you get other options (ability to authenticate with/send from the mail_user address, sieve vacation messages, etc.); just set the forward-to address in the 'cc' field, and set disabledeliver='y' if you don't want it to hit dovecot (required for sieve). Either way works...
     
  3. jnewman67

    jnewman67 Active Member HowtoForge Supporter

    as I've added a lot of "echo" lines in mine trying to figure it out, i believe you mean this line:
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    wish I'd seen that earlier :)
    thanks for the idea for forwarders - my last control panel didn't distinguish between mailboxes or forwarders. you either enabled a mailbox, or didn't - the CC worked for either case. it was convenient - i'll look into that. thanks again.
     

Share This Page