PHP code example of siberfx / mail-sdk-kerioconnect

1. Go to this page and download the library: Download siberfx/mail-sdk-kerioconnect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

siberfx / mail-sdk-kerioconnect example snippets


use Siberfx\MailSdkKerioConnect\Contracts\MailboxProvisioner;
use Siberfx\MailSdkKerioConnect\Contracts\MailTransport;

final class OnboardTenant
{
    public function __construct(
        private readonly MailboxProvisioner $mailboxes,
        private readonly MailTransport $mail,
    ) {}

    public function handle(Tenant $tenant): void
    {
        if (! $this->mailboxes->exists($tenant->domain, 'support')) {
            $this->mailboxes->create(
                domain: $tenant->domain,
                login: 'support',
                password: Str::password(20),
                fullName: "{$tenant->name} Support",
            );
        }

        $this->mail->send(
            to: $tenant->owner_email,
            subject: 'Your mailbox is ready',
            htmlBody: view('mail.mailbox-ready', ['tenant' => $tenant])->render(),
        );
    }
}

use Siberfx\MailSdkKerioConnect\Facades\KerioConnect;

KerioConnect::mail()->send(
    to: '[email protected]',
    subject: 'Welcome',
    htmlBody: '<p>Welcome aboard.</p>',
);

KerioConnect::mailboxes()->create('tenant.test', 'support', $password, 'Tenant Support');

$mail->send(
    to: ['[email protected]', '[email protected]'],
    subject: 'Invoice #123',
    htmlBody: $html,
    options: [
        'from' => '[email protected]',   // must be an address of the SMTP mailbox
        'fromName' => 'Billing',
        'replyTo' => '[email protected]',
        'cc' => '[email protected]',
        'bcc' => ['[email protected]'],
    ],
);

use Symfony\Component\Mime\Email;

$mail->sendRaw(
    (new Email)
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Your invoice')
        ->html($html)
        ->text($plain)
        ->attachFromPath(storage_path('app/invoices/123.pdf'))
);

$mailboxes->list('example.com');                      // all mailboxes on the domain
$mailboxes->find('example.com', 'support');           // one mailbox, or null
$mailboxes->exists('example.com', 'support');         // bool

$mailboxes->create(
    domain: 'example.com',
    login: 'support',
    password: Str::password(20),
    fullName: 'Support Desk',
    isEnabled: true,
);

$mailboxes->setEnabled('example.com', 'support', false);
$mailboxes->setPassword('example.com', 'support', $newPassword);

// Makes [email protected] a valid From address on the operations@ mailbox.
$mailboxes->addEmailAddress('example.com', 'operations', 'noreply');

$result = $rpc->call('Domains.get', [
    'query' => ['fields' => ['id', 'name']],
]);

use Siberfx\MailSdkKerioConnect\Exceptions\KerioConnectException;

try {
    $mailboxes->create('example.com', 'support', $password, 'Support');
} catch (KerioConnectException $e) {
    report($e);
}
bash
php artisan vendor:publish --tag=kerioconnect-config