protected function send() { /** @var EEmailManager $emailManager */ $emailManager = Yii::app()->emailManager; $emailManager->email($emailManager->fromEmail, 'EmailManager subject', 'EmailManager message'); $this->codeGuy->seeInDatabase('email_spool', array('subject' => 'EmailManager subject')); $this->assertEquals(EmailSpool::model()->unpack(EmailSpool::model()->pack('EmailManager message')), 'EmailManager message'); }
protected function update() { $date = time(); $emailSpool = EmailSpool::model()->findByPk($this->emailSpool->id); $emailSpool->transport = 'the transport changed'; $emailSpool->template = 'the template changed'; $emailSpool->priority = 100; $emailSpool->status = 'the status changed'; $emailSpool->model_name = 'the model_name changed'; $emailSpool->model_id = 'the model_id changed'; $emailSpool->to_address = 'the to_address changed'; $emailSpool->from_address = 'the from_address changed'; $emailSpool->subject = 'the subject changed'; $emailSpool->message = 'the message changed'; $emailSpool->sent = $date; $emailSpool->created = $date; $save = $emailSpool->save(); $this->assertTrue($save); $this->codeGuy->seeInDatabase('email_spool', array('transport' => 'the transport changed', 'template' => 'the template changed', 'priority' => 100, 'status' => 'the status changed', 'model_name' => 'the model_name changed', 'model_id' => 'the model_id changed', 'to_address' => 'the to_address changed', 'from_address' => 'the from_address changed', 'subject' => 'the subject changed', 'message' => 'the message changed', 'sent' => $date, 'created' => $date)); }
/** * Deliver pending EmailSpool records. */ public function spool($limit = 10) { $done = 0; // find all the spooled emails $emailSpools = EmailSpool::model()->findAll(array('condition' => 't.status=:status', 'params' => array(':status' => 'pending'), 'order' => 't.priority DESC, t.created ASC', 'limit' => $limit)); foreach ($emailSpools as $emailSpool) { // update status to processing $emailSpool->status = 'processing'; $emailSpool->save(false); // build the message $swiftMessage = $emailSpool->unpack($emailSpool->message); // send the email $sent = $this->deliver($swiftMessage, $emailSpool->transport); // update status and save $emailSpool->status = $sent ? 'emailed' : 'error'; $emailSpool->sent = time(); $emailSpool->save(false); $done++; } return $done; }
<?php /** * @var $this EmailStatsController * * @author Brett O'Donnell <*****@*****.**> * @author Zain Ul abidin <*****@*****.**> * @copyright 2013 Mr PHP * @link https://github.com/cornernote/yii-email-module * @license BSD-3-Clause https://raw.github.com/cornernote/yii-email-module/master/LICENSE * * @package yii-email-module */ Yii::app()->user->setState('index.emailStats', Yii::app()->request->requestUri); $this->pageTitle = Yii::t('email', 'Stats'); $tabs = array(); $transports = Yii::app()->emailManager->transports; foreach ($transports as $transportName => $transport) { $attributes = array(); for ($day = 0; $day < 90; $day++) { $date = date('Y-m-d', strtotime('-' . $day . 'days')); $criteria = new CDbCriteria(); $criteria->compare('transport', $transportName); $criteria->addBetweenCondition('created', strtotime(date('Y-m-d 00:00:00', strtotime($date))), strtotime(date('Y-m-d 23:59:59', strtotime($date)))); $count = EmailSpool::model()->count($criteria); $attributes[] = array('label' => $date, 'value' => $count); } $tabs[] = array('label' => $transportName, 'content' => $this->widget('DetailView', array('data' => false, 'attributes' => $attributes), true)); } $tabs[0]['active'] = true; $this->widget('bootstrap.widgets.TbTabs', array('tabs' => $tabs));