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'); }
/** * Creates an EmailSpool based on a Swift_Message. * Can optionally relate the EmailSpool to a model_id and model_name by passing an CActiveRecord into $model. * @param Swift_Message $swiftMessage * @param CActiveRecord|null $model * @return EmailSpool */ public function getEmailSpool($swiftMessage, $model = null) { $emailSpool = new EmailSpool(); $emailSpool->created = time(); $emailSpool->status = 'pending'; $emailSpool->subject = $swiftMessage->getSubject(); $emailSpool->message = $emailSpool->pack($swiftMessage); $emailSpool->to_address = json_encode($swiftMessage->getTo()); $emailSpool->from_address = json_encode($swiftMessage->getFrom()); if ($model) { $emailSpool->model_name = get_class($model); $emailSpool->model_id = is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey(); } return $emailSpool; }
<?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));
public static function sendMail($dbh, $cron, $file, $subject = "[CRON MANAGER] Task Completed") { require_once (GenConfig::LOCATION == 2 ? System::L_SYSTEM_PATH : System::D_SYSTEM_PATH) . "includes/emailSpool/class.emailSpool.php"; $email = new EmailSpool(); $email->fromName = "TrafficSynergy CRON Manager"; $email->fromAdd = "*****@*****.**"; $email->toAddress = $cron["email_address"]; # self::getToAddress($id, $dbh); # can be , seperated ; seperated or array $cc = self::getCCAddresses($cron["cron_id"], $dbh); $bcc = self::getBCCAddresses($cron["cron_id"], $dbh); if (!empty($cc)) { $email->ccAddress = $cc; # can be , seperated ; seperated or array } if (!empty($bcc)) { $email->bccAddress = $bcc; # can be , seperated ; seperated or array } $email->fileAttach = array($file); # array of filenames # $email->htmlBody = file_get_contents($file); #html body - if you want to send an text email set only the textBody $email->textBody = file_get_contents($file); #this can be the alt Body or text only body $email->priority = 4; #1 is low 5 is high default 3 $email->subject = $subject; $email->program = "CronManager"; $email->key = $cron["cron_id"]; # $id; # (Optional) A key to identify this email in the context of the program [idnumber/transactionID] $email->ref = ""; # (Optional) Ref to who send the email. Blank for auto email if ($_id = $email->submitEmail()) { # returns an unique id that is a reference to the inserted email SR_Agent::Log(GenConfig::API, SystemReporter::MSG_MESSAGE, "Mail message sent, id #" . $_id); return "Message was sent successfully with ID : %lightblue%{$_id}%white% \n"; } else { SR_Agent::Log(GenConfig::API, SystemReporter::MSG_ERROR, "There was an error sending the message :" . $email->error . "\n"); return "There was an error sending the message : %red%" . $email->error . "%white%\n"; } }
protected function search() { $emailSpool = new EmailSpool('search'); $emailSpool->transport = 'the transport changed'; $dataProvider = $emailSpool->search(); $data = $dataProvider->getData(); $this->assertEquals($data[0]->transport, 'the transport changed'); $this->assertEquals($data[0]->template, 'the template changed'); $this->assertEquals($data[0]->priority, 100); $this->assertEquals($data[0]->status, 'the status changed'); $this->assertEquals($data[0]->model_name, 'the model_name changed'); $this->assertEquals($data[0]->model_id, 'the model_id changed'); $this->assertEquals($data[0]->to_address, 'the to_address changed'); $this->assertEquals($data[0]->from_address, 'the from_address changed'); $this->assertEquals($data[0]->subject, 'the subject changed'); $this->assertEquals($data[0]->message, 'the message changed'); }