Inheritance: extends Cake\Mailer\Email, use trait Cake\Log\LogTrait
Example #1
0
 /**
  * Test sending emails via CLI and Queue transport.
  *
  * @return void
  */
 public function complete_email()
 {
     Configure::write('debug', 0);
     $Email = new Email();
     $Email->to('*****@*****.**', 'Mark Test');
     $Email->subject('Testing Message');
     $host = Configure::read('App.host');
     if ($host) {
         $Email->domain($host);
     }
     $config = $Email->config();
     if (!isset($config['queue'])) {
         return $this->error('queue key in config missing');
     }
     $res = $Email->send('Foo');
     if (!$res) {
         return $this->error('Could not send email: ' . $Email->getError());
     }
     $this->out('YEAH!');
 }
Example #2
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     Log::drop('email');
     Email::drop('test');
     Email::dropTransport('debug');
     Email::dropTransport('test_smtp');
 }
Example #3
0
 /**
  * Set the body of the mail as we send it.
  * Note: the text can be an array, each element will appear as a seperate line in the message body.
  *
  * Do NOT pass a message if you use $this->set() in combination with templates
  *
  * @overwrite
  * @param string/array: message
  * @return bool Success
  */
 public function send($message = null)
 {
     $this->_log = ['to' => $this->_to, 'from' => $this->_from, 'sender' => $this->_sender, 'replyTo' => $this->_replyTo, 'cc' => $this->_cc, 'subject' => $this->_subject, 'bcc' => $this->_bcc, 'transport' => get_class($this->_transport)];
     if ($this->_priority) {
         $this->_headers['X-Priority'] = $this->_priority;
         //$this->_headers['X-MSMail-Priority'] = 'High';
         //$this->_headers['Importance'] = 'High';
     }
     // if not live, just log but do not send any mails //TODO: remove and use Debug Transport!
     if (!Configure::read('Config.live')) {
         $this->_logEmail();
         return true;
     }
     // Security measure to not sent to the actual addressee in debug mode while email sending is live
     if (Configure::read('debug') && Configure::read('Config.live')) {
         $adminEmail = Configure::read('Config.adminEmail');
         if (!$adminEmail) {
             $adminEmail = Configure::read('Config.systemEmail');
         }
         foreach ($this->_to as $k => $v) {
             if ($k === $adminEmail) {
                 continue;
             }
             unset($this->_to[$k]);
             $this->_to[$adminEmail] = $v;
         }
         foreach ($this->_cc as $k => $v) {
             if ($k === $adminEmail) {
                 continue;
             }
             unset($this->_cc[$k]);
             $this->_cc[$adminEmail] = $v;
         }
         foreach ($this->_bcc as $k => $v) {
             if ($k === $adminEmail) {
                 continue;
             }
             unset($this->_bcc[$k]);
             $this->_bcc[] = $v;
         }
     }
     try {
         $this->_debug = parent::send($message);
     } catch (\Exception $e) {
         $this->_error = $e->getMessage();
         $this->_error .= ' (line ' . $e->getLine() . ' in ' . $e->getFile() . ')' . PHP_EOL . $e->getTraceAsString();
         // always log report
         $this->_logEmail(LogLevel::ERROR);
         // log error
         $this->log($this->_error, LogLevel::ERROR);
         return false;
     }
     if (!empty($this->_profile['logReport'])) {
         $this->_logEmail();
     }
     return true;
 }
Example #4
0
 /**
  * Wrap to protected method
  *
  * @param string $text
  * @param int $length
  * @return array
  */
 public function wrap($text, $length = Email::LINE_LENGTH_MUST)
 {
     return parent::_wrap($text, $length);
 }