Script create email in PHP - ISP 3.2

Discussion in 'Developers' Forum' started by KilioZ, Oct 11, 2020.

  1. KilioZ

    KilioZ New Member

    Hello,
    I would like to know how to create an email address via ISPConfig 3.2 in PHP.

    I have seen some things, but it is still "website", not email address only.

    Thank you,
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    You can find API usage examples for various functions incl. functions to add email accounts in the remote_client folder of the ISPConfig tar.gz file.
     
  3. KilioZ

    KilioZ New Member

    Hello, I have a problem:
    If I use: HTTPS:// I have:
    login_failedThe login failed. Username or password wrong. SOAP Error: The login failed. Username or password wrong.

    If I use: HTTP:// I have:
    SOAP Error: Bad Request

    My code is:

    PHP:
    $username 'ID_USER_C4';
                                            
    $password 'PASSWORD_USER_C4';
                                            
    $soap_location 'http://url_domain.ext:8080/remote/index.php';
                                            
    $soap_uri 'http://url_domain.ext:8080/remote/';


                                            
    $client = new SoapClient(null, array('location' => $soap_location,
                                                    
    'uri'      => $soap_uri,
                                                    
    'trace' => 1,
                                                    
    'exceptions' => 1));


                                            try {
                                                if(
    $session_id $client->login($username$password)) {
                                                    echo 
    'Logged successfull. Session ID:'.$session_id.'<br />';
                                                }

                                                
    //* Set the function parameters.
                                                
    $client_id "4"// 4 BECAUSE I USE C4
                                              
    $password0 $request->GetPost('dvtme__email_mail_password');
                                                
    $params = array(
                                                    
    'server_id' => 1,
                                                    
    'email' => $request->GetPost('dvtme__email_mail_username').'@my_domain.ext',
                                                    
    'login' => $request->GetPost('dvtme__email_mail_username').'@my_domain.ext',
                                                    
    'password' => $password0,
                                                    
    'name' => $request->GetPost('dvtme__email_mail_username').' by '.$user['pseudo'],
                                                    
    'uid' => 5000,
                                                    
    'gid' => 5000,
                                                    
    'maildir' => '/var/vmail/my_domain.ext/'.$request->GetPost('dvtme__email_mail_username').'',
                                                    
    'quota' => 5242880,
                                                    
    'cc' => '',
                                                    
    'homedir' => '/var/vmail',
                                                    
    'autoresponder' => 'n',
                                                    
    'autoresponder_start_date' => '',
                                                    
    'autoresponder_end_date' => '',
                                                    
    'autoresponder_text' => 'hallo',
                                                    
    'autoresponder_subject' => 'Out of office reply',
                                                    
    'move_junk' => 'n',
                                                    
    'custom_mailfilter' => 'spam',
                                                    
    'postfix' => 'n',
                                                    
    'access' => 'n',
                                                    
    'disableimap' => 'n',
                                                    
    'disablepop3' => 'n',
                                                    
    'disabledeliver' => 'n',
                                                    
    'disablesmtp' => 'n'
                                                
    );
                                                
    $mailuser_id $client->mail_user_add($session_id$client_id$params);

                                                echo 
    "New user: ".$mailuser_id."<br>";

                                                if(
    $client->logout($session_id)) {
                                                    
    //echo 'Logged out.<br />';
                                                
    }
                                            } catch (
    SoapFault $e) {
                                                echo 
    $client->__getLastResponse();
                                                die(
    'SOAP Error: '.$e->getMessage());
                                            }
    What the problem @till ?
     
  4. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    You have to use a username and password for a remote user, which you can add under System - Remote Users. You can't use client logins for the API.

    You also have to grant the correct rights to the needed functions for your remote user.

    The http error is probably caused because you are using HTTPS for the panel. So use HTTPS with a correct username and password.
     

Share This Page