public function preview($e)
 {
     $configName = $e['EmailQueue']['config'];
     $template = $e['EmailQueue']['template'];
     $layout = $e['EmailQueue']['layout'];
     $headers = empty($e['EmailQueue']['headers']) ? array() : (array) $e['EmailQueue']['headers'];
     $theme = empty($e['EmailQueue']['theme']) ? null : (string) $e['EmailQueue']['theme'];
     if (empty($theme)) {
         $theme = '';
     }
     $email = new CakeEmail($configName);
     $email->transport('Debug')->to($e['EmailQueue']['to'])->subject($e['EmailQueue']['subject'])->template($template, $layout)->emailFormat($e['EmailQueue']['format'])->addHeaders($headers)->theme($theme)->messageId(false)->returnPath($email->from())->viewVars($e['EmailQueue']['template_vars']);
     $return = $email->send();
     $this->out('Content:');
     $this->hr();
     $this->out($return['message']);
     $this->hr();
     $this->out('Headers:');
     $this->hr();
     $this->out($return['headers']);
     $this->hr();
     $this->out('Data:');
     $this->hr();
     debug($e['EmailQueue']['template_vars']);
     $this->hr();
     $this->out();
 }
 public function handleException(Exception $exception, $shutdown = false)
 {
     $this->_exception = $exception;
     $email = new CakeEmail('error');
     $prefix = Configure::read('ExceptionNotifier.prefix');
     $from = $email->from();
     if (empty($from)) {
         $email->from('*****@*****.**', 'Exception Notifier');
     }
     $subject = $email->subject();
     if (empty($subject)) {
         $email->subject($prefix . '[' . date('Ymd H:i:s') . '][' . $this->_getSeverityAsString() . '][' . ExceptionText::getUrl() . '] ' . $exception->getMessage());
     }
     if ($this->useSmtp) {
         $email->transport('Smtp');
         $email->config($this->smtpParams);
     }
     $text = ExceptionText::getText($exception->getMessage(), $exception->getFile(), $exception->getLine());
     $email->send($text);
     // return Exception.handler
     if ($shutdown || !$this->_exception instanceof ErrorException) {
         $config = Configure::read('Exception');
         $handler = $config['handler'];
         if (is_string($handler)) {
             call_user_func($handler, $exception);
         } elseif (is_array($handler)) {
             call_user_func_array($handler, $exception);
         }
     }
 }
Пример #3
0
 public function index()
 {
     $email = new CakeEmail();
     // 		$email->transport('Debug');
     $email->transport('Mail');
     $email->from('*****@*****.**');
     $email->to('*****@*****.**');
     $email->subject('これはテストメールです');
     $messages = $email->send('これはテストメールの本文です。');
     $this->set('messages', $messages);
 }
Пример #4
0
 /**
  * Send mail
  *
  * @param CakeEmail $email CakeEmail
  * @return array
  */
 public function send(CakeEmail $email)
 {
     if (!empty($this->_config['queue'])) {
         $this->_config = $this->_config['queue'] + $this->_config;
         $email->config((array) $this->_config['queue'] + ['queue' => []]);
         unset($this->_config['queue']);
     }
     $transport = $this->_config['transport'];
     $email->transport($transport);
     $QueuedTask = ClassRegistry::init('Queue.QueuedTask');
     $result = $QueuedTask->createJob('Email', ['transport' => $transport, 'settings' => $email]);
     $result['headers'] = '';
     $result['message'] = '';
     return $result;
 }
 public function preview($e)
 {
     $configName = $e['EmailQueue']['config'];
     $template = $e['EmailQueue']['template'];
     $layout = $e['EmailQueue']['layout'];
     $email = new CakeEmail($configName);
     $email->transport('Debug')->to($e['EmailQueue']['to'])->subject($e['EmailQueue']['subject'])->template($template, $layout)->emailFormat($e['EmailQueue']['format'])->viewVars($e['EmailQueue']['template_vars']);
     $return = $email->send();
     $this->out('Content:');
     $this->hr();
     $this->out($return['message']);
     $this->hr();
     $this->out('Headers:');
     $this->hr();
     $this->out($return['headers']);
     $this->hr();
     $this->out('Data:');
     $this->hr();
     debug($e['EmailQueue']['template_vars']);
     $this->hr();
     $this->out();
 }
Пример #6
0
/**
 * Send an email using the specified content, template and layout
 *
 * @param string|array $content Either an array of text lines, or a string with contents
 *  If you are rendering a template this variable will be sent to the templates as `$content`
 * @param string $template Template to use when sending email
 * @param string $layout Layout to use to enclose email body
 * @return boolean Success
 */
	public function send($content = null, $template = null, $layout = null) {
		$lib = new CakeEmail();
		$lib->charset = $this->charset;
		$lib->headerCharset = $this->charset;

		$lib->from($this->_formatAddresses((array)$this->from));
		if (!empty($this->to)) {
			$lib->to($this->_formatAddresses((array)$this->to));
		}
		if (!empty($this->cc)) {
			$lib->cc($this->_formatAddresses((array)$this->cc));
		}
		if (!empty($this->bcc)) {
			$lib->bcc($this->_formatAddresses((array)$this->bcc));
		}
		if (!empty($this->replyTo)) {
			$lib->replyTo($this->_formatAddresses((array)$this->replyTo));
		}
		if (!empty($this->return)) {
			$lib->returnPath($this->_formatAddresses((array)$this->return));
		}
		if (!empty($this->readReceipt)) {
			$lib->readReceipt($this->_formatAddresses((array)$this->readReceipt));
		}

		$lib->subject($this->subject)->messageID($this->messageId);
		$lib->helpers($this->_controller->helpers);

		$headers = array('X-Mailer' => $this->xMailer);
		foreach ($this->headers as $key => $value) {
			$headers['X-' . $key] = $value;
		}
		if ($this->date) {
			$headers['Date'] = $this->date;
		}
		$lib->setHeaders($headers);

		if ($template) {
			$this->template = $template;
		}
		if ($layout) {
			$this->layout = $layout;
		}
		$lib->template($this->template, $this->layout)->viewVars($this->_controller->viewVars)->emailFormat($this->sendAs);

		if (!empty($this->attachments)) {
			$lib->attachments($this->_formatAttachFiles());
		}

		$lib->transport(ucfirst($this->delivery));
		if ($this->delivery === 'mail') {
			$lib->config(array('eol' => $this->lineFeed, 'additionalParameters' => $this->additionalParams));
		} elseif ($this->delivery === 'smtp') {
			$lib->config($this->smtpOptions);
		} else {
			$lib->config(array());
		}

		$sent = $lib->send($content);

		$this->htmlMessage = $lib->message(CakeEmail::MESSAGE_HTML);
		if (empty($this->htmlMessage)) {
			$this->htmlMessage = null;
		}
		$this->textMessage = $lib->message(CakeEmail::MESSAGE_TEXT);
		if (empty($this->textMessage)) {
			$this->textMessage = null;
		}

		$this->_header = array();
		$this->_message = array();

		return $sent;
	}
Пример #7
0
 /**
  * Wrapper of CakeEmail object creation and submission.
  * @param $emailData
  * @param string $templateName
  * @param string $to
  * @param string $subjectBlockName
  * @param string $tag
  * @param string $locale
  * @param bool $debug
  * @param array $emailOptions
  * @return string
  * @throws Exception
  */
 public static function sendEmail($emailData, $templateName = '', $to = '', $subjectBlockName = '', $tag = '', $locale = 'en-US', $debug = false, $emailOptions = array())
 {
     if (empty($templateName) || empty($to) || empty($subjectBlockName)) {
         CakeLog::error('CRITICAL EXEPTION: In email library.');
         CakeLog::error('Empty argument passed to email sender.');
         throw new BadMethodCallException('Empty argument passed to email sender.', 1);
         return false;
     }
     // Since getting the data from Drupal happens in-line we need to check
     // for errors by seeing if we only get log_info back and nothing else.
     if (!empty($tag)) {
         $drupalData = array();
         DruniqueAPIUtil::getData(['api_url' => 'email_text.json', 'params' => ['tag' => $tag], 'locale' => $locale], $drupalData);
         if (sizeof($drupalData) <= 1) {
             CakeLog::error('CRITICAL EXEPTION: In email library.');
             CakeLog::error('Unable to get view variables from CMS.');
             throw new Exception('Unable to get view variables from CMS.', 1);
             return false;
         }
         $emailData['email_text'] = $drupalData;
     }
     $email = new CakeEmail('default');
     $subject = DruniqueAPIUtil::content($subjectBlockName, $emailData['email_text']);
     $subject = preg_replace('/[\\pZ\\pC]/u', ' ', $subject);
     if ($debug) {
         $email->transport('Debug');
     }
     // Make sure format is set correctly based on existence of templates.
     $format = 'both';
     $htmlTemplateExists = is_readable(APP . "View/Emails/html/{$templateName}.ctp");
     $textTemplateExists = is_readable(APP . "View/Emails/text/{$templateName}.ctp");
     if (!$htmlTemplateExists && !$textTemplateExists) {
         CakeLog::error('CRITICAL ERROR: In email library.');
         CakeLog::error("Unable to find email template named {$templateName}.ctp");
         return false;
     } elseif (!$htmlTemplateExists && $textTemplateExists) {
         $format = 'text';
     } elseif ($htmlTemplateExists && !$textTemplateExists) {
         $format = 'html';
     }
     $email->template($templateName, 'default')->emailFormat($format)->to($to)->subject(html_entity_decode($subject, ENT_QUOTES))->viewVars($emailData);
     if (isset($emailOptions['bcc'])) {
         $email->bcc($emailOptions['bcc']);
     }
     if (isset($emailOptions['cc'])) {
         $email->cc($emailOptions['cc']);
     }
     try {
         $response = $email->send();
         if ($debug) {
             return $response;
         }
         if ($response) {
             $result = 'Email was sent successfully';
         } else {
             $result = 'Email failed to send without exceptions';
             CakeLog::error('CRITICAL ERROR: Email library failed to send an email without exception.');
             Cakelog::error(print_r($email, true));
         }
     } catch (Exception $e) {
         $result = 'Email failed with exception: ' . print_r($e->getMessage(), true);
         CakeLog::error('CRITICAL ERROR: In email library.');
         CakeLog::error($e->getMessage());
     }
     return $result;
 }
Пример #8
0
 /**
  * Sends out an email notifying you of a new comment.
  *
  * @param Model $model
  * @param array $data
  * @param int $status
  * @param int $points
  */
 public function notify(Model $model, $data, $status, $points = 0)
 {
     $settings = $this->settings[$model->alias];
     $columnMap = $settings['columnMap'];
     if ($settings['model'] && $settings['link'] && $settings['email']) {
         $Article = ClassRegistry::init(Inflector::classify($settings['model']));
         $result = $Article->find('first', array('conditions' => array($columnMap['id'] => $data[$columnMap['foreignKey']]), 'recursive' => -1, 'contain' => false));
         // Build variables
         $link = str_replace('{id}', $result[$Article->alias][$columnMap['id']], $settings['link']);
         if ($settings['useSlug']) {
             $link = str_replace('{slug}', $result[$Article->alias][$columnMap['slug']], $settings['link']);
         }
         $title = $result[$Article->alias][$columnMap['title']];
         $email = $data[$columnMap['email']];
         $author = $data[$columnMap['author']];
         // Send email
         $Email = new CakeEmail();
         $Email->to($settings['email'])->from(array($email => $author))->subject('Comment Approval: ' . $title)->helpers(array('Html', 'Time'))->viewVars(array('settings' => $settings, 'article' => $result, 'comment' => $data, 'link' => $link, 'status' => $status, 'points' => $points));
         if (Configure::read('debug')) {
             $Email->transport('Debug')->config(array('log' => true));
         }
         // Use a custom template
         if (is_string($settings['sendEmail'])) {
             $Email->template($settings['sendEmail'])->emailFormat('both')->send();
             // Send a simple message
         } else {
             $statuses = array_flip($settings['statusMap']);
             $message = sprintf("A new comment has been posted for: %s\n\n", $link);
             $message .= sprintf("Name: %s <%s>\n", $author, $email);
             $message .= sprintf("Status: %s (%s points)\n", $statuses[$status], $points);
             $message .= sprintf("Message:\n\n%s", $data[$columnMap['content']]);
             $Email->send($message);
         }
     }
 }
Пример #9
0
    function smtp_details($username = null)
    {
        $this->loadModel('Company');
        if (!$this->Session->read('User.id')) {
            $record = $this->Company->find('first', array('fields' => 'Company.smtp_setup', 'recursive' => -1));
            if ($record['Company']['smtp_setup'] == 1) {
                $this->Session->setFlash(__('Please login to setup SMTP details'), 'default', array('class' => 'alert-danger'));
                $this->redirect(array('action' => 'login', $username));
            }
            $this->layout = "login";
        }
        $isSmtp = 0;
        $transport = null;
        $SmtpDetail = $this->Company->find('first', array('fields' => array('Company.is_smtp', 'Company.smtp_setup'), 'recursive' => -1));
        if ($SmtpDetail['Company']['smtp_setup'] == 1) {
            $Email = new CakeEmail();
            $Email->config('smtp');
            $transport = $Email->transport('smtp')->config();
        }
        if ($SmtpDetail['Company']['is_smtp'] == 1) {
            $isSmtp = 1;
        }
        $this->set(compact('isSmtp', 'transport'));
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->request->data['User']['is_smtp'] == 0) {
                $this->loadModel('Company');
                $id = $this->Company->find('first', array('fields' => 'Company.id', 'recursive' => -1));
                $this->Company->id = $id;
                $data['Company']['is_smtp'] = 0;
                $this->Company->id;
                $this->Company->save($data);
                $string = '<?php
/**
 * This is email configuration file.
 *
 * Use it to configure email transports of Cake.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Config
 * @since         CakePHP(tm) v 2.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * Email configuration class.
 * You can specify multiple configurations for production, development and testing.
 *
 * transport => The name of a supported transport; valid options are as follows:
 *		Mail 		- Send using PHP mail function
 *		Smtp		- Send using SMTP
 *		Debug		- Do not send the email, just return the result
 *
 * You can add custom transports (or override existing transports) by adding the
 * appropriate file to app/Network/Email. Transports should be named "YourTransport.php",
 * where "Your" is the name of the transport.
 *
 * from =>
 * The origin email. See CakeEmail::from() about the valid values
 *
 */
class EmailConfig {

	public $default = array(
		"transport" => "Mail",
		"from" => array("' . $this->request->data['User']['default_user'] . '" => "FlinkISO"),
		//"charset" => "utf-8",
		//"headerCharset" => "utf-8",
	);

	public $smtp = array(

        "transport" => "Smtp",
		"from" => array("*****@*****.**" => "FlinkISO"),
		"host" => "smtp.yourserver.com",
		"port" => 25,
		"timeout" => 30,
		"username" => "*****@*****.**",
		"password" => "secret",
		"client" => null,
		"log" => false,
	);

	public $fast = array(
		"from" => "you@localhost",
		"sender" => null,
		"to" => null,
		"cc" => null,
		"bcc" => null,
		"replyTo" => null,
		"readReceipt" => null,
		"returnPath" => null,
		"messageId" => true,
		"subject" => null,
		"message" => null,
		"headers" => null,
		"viewRender" => null,
		"template" => false,
		"layout" => false,
		"viewVars" => null,
		"attachments" => null,
		"emailFormat" => null,
		"transport" => "Smtp",
		"host" => "localhost",
		"port" => 25,
		"timeout" => 30,
		"username" => "user",
		"password" => "secret",
		"client" => null,
		"log" => true,
		//"charset" => "utf-8",
		//"headerCharset" => "utf-8",
	);



}';
                $fp = fopen(APP . "Config/email.php", "w");
                fwrite($fp, $string);
                fclose($fp);
                $this->Session->setFlash(__('Default email setup done successfully.'), 'default', array('class' => 'alert-success'));
                $this->redirect(array('controller' => 'users', 'action' => 'login', $username));
            } else {
                $this->loadModel('Company');
                $id = $this->Company->find('first', array('fields' => 'Company.id', 'recursive' => -1));
                $this->Company->id = $id;
                $data['Company']['is_smtp'] = 1;
                $this->Company->id;
                $this->Company->save($data);
                $string = '<?php
/**
 * This is email configuration file.
 *
 * Use it to configure email transports of Cake.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Config
 * @since         CakePHP(tm) v 2.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * Email configuration class.
 * You can specify multiple configurations for production, development and testing.
 *
 * transport => The name of a supported transport; valid options are as follows:
 *		Mail 		- Send using PHP mail function
 *		Smtp		- Send using SMTP
 *		Debug		- Do not send the email, just return the result
 *
 * You can add custom transports (or override existing transports) by adding the
 * appropriate file to app/Network/Email. Transports should be named "YourTransport.php",
 * where "Your" is the name of the transport.
 *
 * from =>
 * The origin email. See CakeEmail::from() about the valid values
 *
 */
class EmailConfig {

	public $default = array(
		"transport" => "Mail",
		"from" => array("*****@*****.**" => "FlinkISO"),
		//"charset" => "utf-8",
		//"headerCharset" => "utf-8",
	);

	public $smtp = array(

        "transport" => "Smtp",
		"from" => array("' . $this->request->data['User']['smtp_user'] . '" => "FlinkISO"),
		"host" => "' . $this->request->data['User']['smtp_host'] . '",
		"port" => ' . $this->request->data['User']['port'] . ',
		"timeout" => 30,
		"username" => "' . $this->request->data['User']['smtp_user'] . '",
		"password" => "' . $this->request->data['User']['smtp_password'] . '",
		"client" => null,
		"log" => false,
	);

	public $fast = array(
		"from" => "you@localhost",
		"sender" => null,
		"to" => null,
		"cc" => null,
		"bcc" => null,
		"replyTo" => null,
		"readReceipt" => null,
		"returnPath" => null,
		"messageId" => true,
		"subject" => null,
		"message" => null,
		"headers" => null,
		"viewRender" => null,
		"template" => false,
		"layout" => false,
		"viewVars" => null,
		"attachments" => null,
		"emailFormat" => null,
		"transport" => "Smtp",
		"host" => "localhost",
		"port" => 25,
		"timeout" => 30,
		"username" => "user",
		"password" => "secret",
		"client" => null,
		"log" => true,
		//"charset" => "utf-8",
		//"headerCharset" => "utf-8",
	);



}';
                $fp = fopen(APP . "Config/email.php", "w");
                fwrite($fp, $string);
                fclose($fp);
                $this->loadModel('Employee');
                $userData = $this->Employee->find('first', array('recursive' => -1));
                if ($userData['Employee']['office_email'] != '') {
                    $email = $userData['Employee']['office_email'];
                } else {
                    if ($userData['Employee']['personal_email'] != '') {
                        $email = $userData['Employee']['personal_email'];
                    }
                }
                if ($email) {
                    try {
                        App::uses('CakeEmail', 'Network/Email');
                        $EmailConfig = new CakeEmail("smtp");
                        $EmailConfig->to($email);
                        $EmailConfig->subject('FlinkISO: Smtp Setup details');
                        $EmailConfig->template('smtpSetup');
                        $EmailConfig->viewVars(array('name' => $userData['Employee']['name']));
                        $EmailConfig->emailFormat('html');
                        $EmailConfig->send();
                        $companyData = array();
                        $companyData['id'] = $userData['Employee']['company_id'];
                        $companyData['smtp_setup'] = 1;
                        $this->loadModel('Company');
                        $this->Company->save($companyData, false);
                        $this->Session->setFlash(__('SMTP setup done successfully.'), 'default', array('class' => 'alert-success'));
                        $this->redirect(array('controller' => 'users', 'action' => 'login', $username));
                    } catch (Exception $e) {
                        $exceptionMessage = $e->getMessage();
                        $invalidPass = substr($exceptionMessage, 0, 15);
                        $companyData = array();
                        $companyData['id'] = $userData['Employee']['company_id'];
                        $companyData['smtp_setup'] = 0;
                        $this->loadModel('Company');
                        $this->Company->save($companyData, false);
                        if (($invalidPass === 'SMTP Error: 535') == 1) {
                            $this->Session->setFlash(__('Can not connect with SMTP server: Invalid password'), 'default', array('class' => 'alert-danger'));
                        } else {
                            $this->Session->setFlash(__('Can not connect with SMTP server: ' . $e->getMessage()), 'default', array('class' => 'alert-danger'));
                        }
                    }
                }
            }
        }
        $isSmtp = 0;
        $transport = null;
        $default_transport = null;
        $SmtpDetail = $this->Company->find('first', array('fields' => array('Company.is_smtp', 'Company.smtp_setup'), 'recursive' => -1));
        $Email = new CakeEmail();
        if ($SmtpDetail['Company']['is_smtp'] == 1) {
            $Email->config('smtp');
            $transport = $Email->transport('smtp')->config();
        } else {
            $Email->config('default');
            $default_transport = $Email->transport('default')->config();
        }
        if ($SmtpDetail['Company']['is_smtp'] == 1) {
            $isSmtp = 1;
        }
        $this->set(compact('isSmtp', 'transport', 'default_transport', 'username'));
    }