/**
  * Send mail using Mandrill (by MailChimp)
  *
  * @param \Cake\Network\Email\Email $email Cake Email
  * @return array
  */
 public function send(Email $email)
 {
     $this->transportConfig = Hash::merge($this->transportConfig, $this->_config);
     // Initiate a new Mandrill Message parameter array
     $message = ['html' => $email->message(\Cake\Network\Email\Email::MESSAGE_HTML), 'text' => $email->message(\Cake\Network\Email\Email::MESSAGE_TEXT), 'subject' => $this->_decode($email->subject()), 'from_email' => key($email->from()), 'from_name' => current($email->from()), 'to' => [], 'headers' => ['Reply-To' => is_null(key($email->replyTo())) ? key($email->from()) : key($email->replyTo())], 'recipient_metadata' => [], 'attachments' => [], 'images' => []];
     // Merge Mandrill Parameters
     $message = array_merge($message, Hash::merge($this->defaultParameters, $email->profile()['Mandrill']));
     // Add receipients
     foreach (['to', 'cc', 'bcc'] as $type) {
         foreach ($email->{$type}() as $mail => $name) {
             $message['to'][] = ['email' => $mail, 'name' => $name, 'type' => $type];
         }
     }
     // Attachments
     $message = $this->_attachments($email, $message);
     // Create a new scoped Http Client
     $this->http = new Client(['host' => 'mandrillapp.com', 'scheme' => 'https', 'headers' => ['User-Agent' => 'CakePHP Mandrill Plugin']]);
     // Sending as a template? Then in case we find mail content, we add this as a 'template_content'.
     // In you Mandrill template, use <div mc:edit="content"></div> to get the contents of your email
     if (!is_null($message['template_name']) && $message['html']) {
         if (!isset($message['template_content']) || !is_array($message['template_content'])) {
             $message['template_content'] = [];
         }
         $message['template_content'][] = ['name' => 'content', 'content' => $message['html']];
     }
     // Are we sending a template?
     if (!is_null($message['template_name']) && !empty($message['template_content'])) {
         return $this->_sendTemplate($message, $this->transportConfig['async'], $this->transportConfig['ip_pool'], $message['send_at']);
     } else {
         return $this->_send($message, $this->transportConfig['async'], $this->transportConfig['ip_pool'], $message['send_at']);
     }
 }
Esempio n. 2
0
 /**
  * Prepares the message body.
  *
  * @return string
  */
 protected function _prepareMessage()
 {
     $lines = $this->_cakeEmail->message();
     $messages = array();
     foreach ($lines as $line) {
         if (!empty($line) && $line[0] === '.') {
             $messages[] = '.' . $line;
         } else {
             $messages[] = $line;
         }
     }
     return implode("\r\n", $messages);
 }
Esempio n. 3
0
 /**
  * Send mail
  *
  * @param \Cake\Network\Email\Email $email Cake Email
  * @return array
  */
 public function send(Email $email)
 {
     $eol = PHP_EOL;
     if (isset($this->_config['eol'])) {
         $eol = $this->_config['eol'];
     }
     $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
     $to = $headers['To'];
     unset($headers['To']);
     foreach ($headers as $key => $header) {
         $headers[$key] = str_replace(array("\r", "\n"), '', $header);
     }
     $headers = $this->_headersToString($headers, $eol);
     $subject = str_replace(array("\r", "\n"), '', $email->subject());
     $to = str_replace(array("\r", "\n"), '', $to);
     $message = implode($eol, $email->message());
     $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
     $this->_mail($to, $subject, $message, $headers, $params);
     return array('headers' => $headers, 'message' => $message);
 }