WebMail Pro 7 documentation

Users

API reference on CApiUsersManager class

WebMail Pro allows for manipulating user accounts and their settings. In the simplest case, when you need to allow for logging in programmatically, these methods will not be used, but they allow for better control over the accounts. It is assumed that user account data are inherited from default domain or, in case of WebMail Pro, from specific domain added to the database previously.

Below you'll find a complete walkthrough for creating user account. The approach for invoking API manager for users is a common point for any methods here. Note that creating user accounts can optionally include checking account credentials against the mailserver - and the check is omitted in this example.

include_once '/var/www/webmail/libraries/afterlogic/api.php';
if (class_exists('CApi') && CApi::IsValid()) {
    $oApiDomainsManager = CApi::Manager('domains');
    $oApiUsersManager = CApi::Manager('users');

    $oDomain = $oApiDomainsManager->getDomainByName('domain.com');
    /* Or, you can access default domain instead */
    /* $oDomain = $oApiDomainsManager->getDefaultDomain(); */
    if ($oDomain) {
        $oAccount = new CAccount($oDomain);
        
        $oAccount->Email = 'test@domain.com';
        $oAccount->IncomingMailLogin = 'test@domain.com';
        $oAccount->IncomingMailPassword = 'password';
        
        if ($oApiUsersManager->createAccount($oAccount, false)) {
            echo 'Account '.$oAccount->Email.' is created successfully.';
        } else {
            echo $oApiUsersManager->GetLastErrorMessage();
        }
    } else {
        echo 'Domain doesn\'t exist';
    }
} else {
    echo 'WebMail API isn\'t available';
}

In case of WebMail Lite, we can't manipulate domains but you can use getDefaultDomain method to work with default domain.

NOTE: many API methods return boolean values. If not stated otherwise, true/false value stands for success or failure respectively.

API reference on CApiUsersManager class