Aurora Corporate documentation

Managing mail servers and user accounts

If you have some existing web application, you might need to manage mail servers and user accounts of Aurora Corporate from it.

This tutorial focuses on creating mail servers and user accounts. Usually, there's no need to create accounts via API or admin interface - as long as mail server with matching settings is added, users should be able to log into the account and it will automatically be created in Aurora Corporate database. But if, for example, you deploy an instance and need to pre-populate certain mail servers and accounts, the example below should come in handy.

In order to make use of Aurora Corporate API, you'll need to initialize it:

include '/var/www/aurora/system/autoload.php';
\Aurora\System\Api::Init();

Then we require Core and Mail modules:

$oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
$oMailDecorator = \Aurora\Modules\Mail\Module::Decorator();

Now, let's add a mail server:

$mServerCreateResult = $oMailDecorator->CreateServer(
                "mydomain",
                "mail.mydomain.com", 143, false,
                "mail.mydomain.com", 25, false,
                \Aurora\Modules\Mail\Enums\SmtpAuthType::UseUserCredentials,
                "mydomain.com"
            );
$msid = $mServerCreateResult;

In there, we supply:

  • mail server display name;
  • IMAP hostname, port, SSL on/off setting;
  • SMTP hostname, port, SSL on/off setting;
  • SMTP authentication mode;
  • a list of domain names this server will be used for. It can hold multiple values, separated with "\n" character, for example: "domain1.com\ndomain2.com"

If server is added successfully, $msid will hold server identifier, we'll be using it when adding user and email account.

In terms of Aurora Corporate, user and email account are separate entities, user can have multiple email accounts. User's public ID corresponds to their primary email account. And before creating new user, we'll make sure one doesn't exist yet first:

$sEmail = 'user@mydomain.com';
$sPasswd = 'passwordhere';
$mUser = $oCoreDecorator->GetUserByPublicId($sEmail);

If $mUser holds false we can proceed with adding email account for this user:

if ($mUser===false) {
    $UserId = $oCoreDecorator->CreateUser(0, $sEmail);
    $oServer = $oMailDecorator->GetServer($msid);
    $asid = $oMailDecorator->CreateAccount($UserId, '', $sEmail, $sEmail,  $sPasswd, array('ServerId' => $oServer->EntityId));
    echo "User account created";
} else {
    echo "User already exists";
}