tonicforhealth / health-checker-check-email
Emails checker for health-checker
Installs: 10 533
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=5.5
- php-imap/php-imap: ^2.0
- psr/log: ^1.0
- swiftmailer/swiftmailer: ^5.0
- tonicforhealth/health-checker-check: ^0.2.0
- zendframework/zenddiagnostics: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.8|^5.3
This package is not auto-updated.
Last update: 2024-11-21 01:43:09 UTC
README
This is a component for checking email send&receive from smtp service point to imap inbox point.
Installation using Composer
$ composer require tonicforhealth/health-checker-check-email
Requirements
- PHP 5.5 or higher
- ext-imap
Usage
<?php use PhpImap\Mailbox; use TonicHealthCheck\Check\Email\Persist\PersistCollectionToFile; use TonicHealthCheck\Check\Email\Receive\EmailReceiveCheck; use TonicHealthCheck\Check\Email\Send\EmailSendCheck; $checkNode = 'testnode'; $persistCollectionToFile = new PersistCollectionToFile(sys_get_temp_dir()); $transport = Swift_SmtpTransport::newInstance(); $mailer = Swift_Mailer::newInstance($transport); $mailbox = new Mailbox('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', 'username', 'password'); $receiveMaxTime = 300; $sendInterval = 600; $emailSendCheck = new EmailSendCheck( $checkNode, $mailer, $persistCollectionToFile, 'from_test@test.com', 'to_test@test.com', $sendInterval ); $emailReceiveCheck = new EmailReceiveCheck( $checkNode, $mailbox, $persistCollectionToFile, $receiveMaxTime ); while (true) { $resultSend = $emailSendCheck->performCheck(); printf( "Send result is:%s\n", $resultSend->isOk() ? 'true' : sprintf('false error:%s', $resultSend->getError()->getMessage()) ); sleep(10); $resultReceive = $emailReceiveCheck->performCheck(); printf( "Receive result is:%s\n", $resultReceive->isOk() ? 'true' : sprintf('false error:%s', $resultReceive->getError()->getMessage()) ); sleep(60); }