PHP code example of smart / emailreader

1. Go to this page and download the library: Download smart/emailreader 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/ */

    

smart / emailreader example snippets


use Smart\EmailReader\Config\EmailServerConfig;

$configs = (EmailServerConfig())
    ->setDomain('imap.gmail.com')
    ->setPort(993)
    ->setService(EmailServerConfig::IMAP)
    ->setUsername('[email protected]')
    ->setPassword('my_plain_text_password')
    ->setMainMailbox('INDEX')
    ->setProcessedMailbox('Processed');

use Smart\EmailReader\Dispatcher\Dispatcher;

class DispatcherApp extends Dispatcher
{
    public function __construct()
    {
        $this->addDispatcher(new SupportEmailDispatcher());
        //you can add as many dispatchers as you want....
    }
}

use Smart\EmailReader\Dispatcher\Dispatcher;
use Smart\EmailReader\EmailEntity;

class SupportEmailDispatcher extends Dispatcher
{
    public function __construct()
    {
        $this->addHandler('#\[support\-(?<id>[0-9]+)\]#i', [$this, 'handleNewReply']);
    }
    
    public function handleNewReply($matches, EmailEntity $email)
    {
        $ticketId = isset($matches['id']) ? (int)$matches['id'] : null;
        $newReply = $email->getLastReply();
        //your logic here...
    }
}

$emailReader = new Fetch(
    new EmailServerConfig() //check the configuration section
); 

$emailLoggerLogger = new EmailReaderLogger(
    '/log/path_to_your_log_file'
);

//add this in sinergi gearman :

new EmailReaderDispatchJob(
    $emailReader,
    new DispatcherApp(), //your own dispatcher
    $emailLoggerLogger
);


$consoleApp = new ConsoleApplication();
$gearmanDispatcher = '...'; //get your gearman dispatcher

$consoleApp->add(
    new EmailReaderSendCommand(
        $gearmanDispatcher,
        $emailReader
    )
);