WebMail Lite 7 documentation

Batch export of contacts

The code provided here will allow you to export contacts for the users. It can be very helpful if you need to backup user data.

To use the code, you will need to supply the following parameters:


Contacts will only be exported for users in these domains.


Filesystem path contacts will be saved to.

For each exported user, a subdirectory will be created, with email address used for directory name. Contacts are saved as contacts.csv file.

$aDomains=array("mydomain.com", "anotherdomain.com");

include_once './libraries/afterlogic/api.php';

if (class_exists('CApi') && CApi::IsValid())
    $oApiUsersManager = CApi::Manager('users');
    $oApiContactsManager = CApi::Manager('contacts');

    $aUserlist = $oApiUsersManager->getDefaultAccountList();
    foreach ($aUserlist as $oUser)
        $sEmail = $oUser->email;
        $sDomain = \api_Utils::GetDomainFromEmail($sEmail);
        if (in_array($sDomain,$aDomains))
            $oAccount = $oApiUsersManager->getAccountByEmail($sEmail);

            $sStoreDir = $sStorePath.$sEmail;

            $sContacts = $oApiContactsManager->export($oAccount->IdUser,"csv");
            file_put_contents($sStoreDir."/contacts.csv", $sContacts);
    echo 'AfterLogic API isn\'t available';

To import data back into WebMail Lite, you can use sample for importing contacts.