WebMail Pro 8 documentation

Managing identities with PHP API

In WebMail Pro 8, each email account can have multiple identities, and by default it has at least one. You can read more on identities here: How to use or disable identities

The below sample creates a new identity for existing email account. We're assuming that it's the primary email account of the user, i.e. the account they log in with (as user can have multiple email accounts, too).

We identify the account by the email address, and specify details of the identity we need to be added.

$sEmail = 'user@domain.com';
$identity = "userid2@domain.com";
$identityname = "New IDentity";
 
include '/usr/share/afterlogic-pro/system/autoload.php';
\Aurora\System\Api::Init(true);
$oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
$oMailDecorator = \Aurora\Modules\Mail\Module::Decorator();
 
$oUser = $oCoreDecorator->GetUserByPublicId($sEmail);
 
if ($oUser!==false) {
    $iUserId = $oUser->EntityId;
    $oAccount = $oCoreDecorator->GetAccountUsedToAuthorize($sEmail);
    $iAccountId = $oAccount->EntityId;
    $oMailDecorator->CreateIdentity($iUserId, $iAccountId, $identityname, $identity);
} 

NB: As always with using PHP, make sure the include directive holds an actual path to system/autoload.php file.

If we need to delete an identity, we should go through all of them and delete those with matching email:

$sEmail = 'user@domain.com';
$identity = "userid2@domain.com";
 
include '/usr/share/afterlogic-pro/system/autoload.php';
\Aurora\System\Api::Init(true);
$oCoreModule = \Aurora\System\Api::GetModule("Core");
$oMailModule = \Aurora\System\Api::GetModule("Mail");
 
$oUser = $oCoreModule->GetUserByPublicId($sEmail);
$iUserId = $oUser->EntityId;
$oAccount = $oCoreModule->GetAccountUsedToAuthorize($sEmail);
$iAccountId = $oAccount->EntityId;
$aIdentities = $oMailModule->GetIdentities($iUserId);
foreach ($aIdentities as $oIdentity) {
    if (($oIdentity->IdAccount == $iAccountId) && ($oIdentity->Email == $identity)) {
        $oMailModule->DeleteIdentity($iAccountId, $oIdentity->EntityId);
    }
}