tonicforhealth / health-checker-check-email
用于健康检查器的电子邮件检查工具
v0.1.6.1
2016-10-27 10:28 UTC
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-09-26 00:38:55 UTC
README
这是一个组件,用于检查从SMTP服务端到IMAP邮箱端的邮件发送和接收。
使用 Composer 安装
$ composer require tonicforhealth/health-checker-check-email
要求
- PHP 5.5 或更高版本
- ext-imap 扩展
使用方法
<?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); }