MailSuite Pro 7 documentation

PHP API Reference

PHP API of MailSuite Pro allows for performing various tasks which involve accessing user account and processing data related to it, such as email messages, folders, contacts etc. It is assumed that the application which uses PHP API is on the same server MailSuite Pro is installed on.

Entity of each kind is represented by a manager. Complete API Reference holds the full list of managers, the most important managers are:

  ∙ Domains

  ∙ Users

  ∙ Accounts

  ∙ Mail

  ∙ Folders

  ∙ Messages

  ∙ Contacts

  ∙ Calendar

  ∙ Files

The same approach is used for invoking any API manager:

include_once '/var/www/webmail/libraries/afterlogic/api.php';
if (class_exists('CApi') && CApi::IsValid()) {
    $oApiCalendarManager = CApi::Manager('filestorage');
    ...
} else {
    echo 'AfterLogic API isn\'t available';
}

In the majority of API managers, many methods return boolean values and, if not stated otherwise, bool value true/false stands for success or failure respectively.

MailSuite Pro documentation contains various examples of using PHP API, such as getting number of all or unread mails:

    include_once __DIR__.'/../libraries/afterlogic/api.php';
	if (class_exists('CApi') && CApi::IsValid())
	{
		$sEmail = 'user@domain.com';
		$sPassword = '12345';
		$sFolder = 'INBOX';

		try
		{
			$oApiIntegratorManager = CApi::Manager('integrator');
			$oAccount = $oApiIntegratorManager->LoginToAccount($sEmail, $sPassword);
			if ($oAccount)
			{
				$oApiMailManager = CApi::Manager('mail');
				$aData = $oApiMailManager->getFolderInformation($oAccount, $sFolder);

				echo '<b>'.$oAccount->Email.':</b><br />';
				if (is_array($aData) && 4 === count($aData))
				{
					echo '<pre>';
					echo 'Folder:   '.$sFolder."\n";
					echo 'Count:    '.$aData[0]."\n";
					echo 'Unread:   '.$aData[1]."\n";
					echo 'UidNext:  '.$aData[2]."\n";
					echo 'Hash:     '.$aData[3];
					echo '</pre>';
				}
			}
			else
			{
				echo $oApiIntegratorManager->GetLastErrorMessage();
			}
		}
		catch (Exception $oException)
		{
			echo $oException->getMessage();
		}
	}
	else
	{
		echo 'WebMail API isn\'t available';
	}

PHP API is not the only way to access account data. If your application is not written in PHP, or if it runs on a different server, you can use Web API which operates over HTTP/HTTPS.

Complete API Reference