tonicforhealth/health-checker-check-email

Emails checker for health-checker

v0.1.6.1 2016-10-27 10:28 UTC

This package is not auto-updated.

Last update: 2024-11-21 01:43:09 UTC


README

License Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight

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);
}