Skip to content
Nguyen Van Nguyen edited this page Aug 30, 2022 · 4 revisions

Examples of common tasks

Admin

Create new user

       $username = 'test';
       $domain = 'zimbra-1.zimbra';
       $password = 'testpass';
       $adminApi = new AdminApi('https://192.168.0.150:7071/service/admin/soap');   
       $adminApi->auth('admin', 'adminpass');
       $adminApi->createAccount($username . '@' . $domain, $password);

Create new domain

       $domain = 'zimbra-1.zimbra';
       $adminApi = new AdminApi('https://192.168.0.150:7071/service/admin/soap');   
       $adminApi->auth('admin', 'adminpass');
       $adminApi->createDomain($domain);

Create new alias

       $accountID = See down;
       $domain = 'zimbra-1.zimbra';
       $alias = 'test2';
       $adminApi = new AdminApi( 'https://192.168.0.150:7071/service/admin/soap');   
       $adminApi->auth('admin', 'adminpass');   
       $adminApi->addAccountAlias($accountID, $alias . '@' . $domain);

Account

Get account ID by name

       $name = 'test';
       $adminApi = new AdminApi('https://192.168.0.150:7071/service/admin/soap');   
       $adminApi->auth('admin', 'adminpass'); 
       $account = new AccountSelector(AccountBy::NAME(), $name);
       $response = $adminApi->getAccount($account);
       $accountID = $response->getAccount()->getId();

Send Email

       $account = new AccountSelector(AccountBy::NAME(), $username . '@' . $domain);
       $api = new MailApi('https://192.168.0.150/service/soap');
       $api->auth($account, 'user password');
       $mp = new MimePartInfo ( null, 'multipart/alternative' );
       $mp->addMimePart ( new MimePartInfo ( null, 'text/plain', 'Email Body Here' ) );
       $tomsg = new MsgToSend();
       $tomsg->setSubject($subject)
       ->addEmail(new EmailAddrInfo('Target Email', AddressType::TO(), 'Name of target or email again'))
       ->setMimePart($mp);
       $api->sendMsg($tomsg);