PHP code example of k3roulas / email-watcher

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

    

k3roulas / email-watcher example snippets


// example with a gmail account
$port = 993;
$email = '[email protected]';
$password = 'IAmNotDavidGuetta';
$filename = './lastuid.json';
$server = 'imap.gmail.com';

// Nominal usage
$newEmailWatcher = new \K3roulas\EmailWatcher\NewEmailWatcherDump();

$emailWatcher = new \K3roulas\EmailWatcher\Watcher();
$emailWatcher->setServer($server)
    ->setPort($port)
    ->setEmail($email)
    ->setPassword($password)
    ->setFilename($filename)
    ->setProtocol('imap')
    ->setNewEmailWatcher($newEmailWatcher)
    ->init();

$emailWatcher->process();


// Use another persitence service : Create your own class that implement LastUidPersistInterface
$lastUidPersist = new MyPersitenceService();
$newEmailWatcher = new \K3roulas\EmailWatcher\NewEmailWatcherDump();

$emailWatcher = new \K3roulas\EmailWatcher\Watcher();
$emailWatcher->setServer($server)
    ->setPort($port)
    ->setEmail($email)
    ->setPassword($password)
    ->setProtocol('imap')
    ->setNewEmailWatcher($newEmailWatcher)
    ->setLastUidPersist($lastUidPersist)
    ->init();

$emailWatcher->process();



// You need more complicated options to access to the server @see Fetch/Server package

$fetchServer = new \Fetch\Server($server, $port);
// For example if you use GSSAPI or  NTLM
$fetchServer->setAuthentication($email, $password, false);

$newEmailWatcher = new \K3roulas\EmailWatcher\NewEmailWatcherDump();

$emailWatcher = new \K3roulas\EmailWatcher\Watcher();
$emailWatcher->setFetchServer($fetchServer)
    ->setNewEmailWatcher($newEmailWatcher)
    ->setFilename($filename)
    ->init();

$emailWatcher->process();