protected function setupEmail(Email $email)
 {
     $this->sendgridEmail = new \SendGrid\Email();
     foreach ($email->to() as $e => $n) {
         $this->sendgridEmail->addTo($e, $n);
     }
     foreach ($email->cc() as $e => $n) {
         $this->sendgridEmail->addCc($e, $n);
     }
     foreach ($email->bcc() as $e => $n) {
         $this->sendgridEmail->addBcc($e, $n);
     }
     foreach ($email->from() as $e => $n) {
         $this->sendgridEmail->setFrom($e);
         $this->sendgridEmail->setFromName($n);
     }
     $this->sendgridEmail->setSubject($email->subject());
     $this->sendgridEmail->setText($email->message(Email::MESSAGE_TEXT));
     $this->sendgridEmail->setHtml($email->message(Email::MESSAGE_HTML));
     if ($email->attachments()) {
         foreach ($email->attachments() as $attachment) {
             $this->sendgridEmail->setAttachment($attachment['file'], $attachment['custom_filename']);
         }
     }
 }
 /**
  * TestSend method
  *
  * @return void
  */
 public function testSendWithEmail()
 {
     $config = ['transport' => 'queue', 'charset' => 'utf-8', 'headerCharset' => 'utf-8'];
     $this->QueueTransport->config($config);
     $Email = new Email($config);
     $Email->from('*****@*****.**', 'CakePHP Test');
     $Email->to('*****@*****.**', 'CakePHP');
     $Email->cc(['*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso']);
     $Email->bcc('*****@*****.**');
     $Email->subject('Testing Message');
     $Email->attachments(['wow.txt' => ['data' => 'much wow!', 'mimetype' => 'text/plain', 'contentId' => 'important']]);
     $Email->template('test_template', 'test_layout');
     $Email->subject("L'utilisateur n'a pas pu être enregistré");
     $Email->replyTo('*****@*****.**');
     $Email->readReceipt('*****@*****.**');
     $Email->returnPath('*****@*****.**');
     $Email->domain('cakephp.org');
     $Email->theme('EuroTheme');
     $Email->emailFormat('both');
     $Email->set('var1', 1);
     $Email->set('var2', 2);
     $result = $this->QueueTransport->send($Email);
     $this->assertEquals('Email', $result['jobtype']);
     $this->assertTrue(strlen($result['data']) < 10000);
     $output = unserialize($result['data']);
     $emailReconstructed = new Email($config);
     foreach ($output['settings'] as $method => $setting) {
         call_user_func_array([$emailReconstructed, $method], (array) $setting);
     }
     $this->assertEquals($emailReconstructed->from(), $Email->from());
     $this->assertEquals($emailReconstructed->to(), $Email->to());
     $this->assertEquals($emailReconstructed->cc(), $Email->cc());
     $this->assertEquals($emailReconstructed->bcc(), $Email->bcc());
     $this->assertEquals($emailReconstructed->subject(), $Email->subject());
     $this->assertEquals($emailReconstructed->charset(), $Email->charset());
     $this->assertEquals($emailReconstructed->headerCharset(), $Email->headerCharset());
     $this->assertEquals($emailReconstructed->emailFormat(), $Email->emailFormat());
     $this->assertEquals($emailReconstructed->replyTo(), $Email->replyTo());
     $this->assertEquals($emailReconstructed->readReceipt(), $Email->readReceipt());
     $this->assertEquals($emailReconstructed->returnPath(), $Email->returnPath());
     $this->assertEquals($emailReconstructed->messageId(), $Email->messageId());
     $this->assertEquals($emailReconstructed->domain(), $Email->domain());
     $this->assertEquals($emailReconstructed->theme(), $Email->theme());
     $this->assertEquals($emailReconstructed->profile(), $Email->profile());
     $this->assertEquals($emailReconstructed->viewVars(), $Email->viewVars());
     $this->assertEquals($emailReconstructed->template(), $Email->template());
     //for now cannot be done 'data' is base64_encode on set but not decoded when get from $email
     //$this->assertEquals($emailReconstructed->attachments(),$Email->attachments());
     //debug($output);
     //$this->assertEquals($Email, $output['settings']);
 }
 /**
  * TestSend method
  *
  * @return void
  */
 public function testSendWithEmail()
 {
     $Email = new Email();
     $Email->from('*****@*****.**', 'CakePHP Test');
     $Email->to('*****@*****.**', 'CakePHP');
     $Email->cc(['*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso']);
     $Email->bcc('*****@*****.**');
     $Email->subject('Testing Message');
     $Email->transport('queue');
     $config = $Email->config('default');
     $this->QueueTransport->config($config);
     $result = $this->QueueTransport->send($Email);
     $this->assertEquals('Email', $result['job_type']);
     $this->assertTrue(strlen($result['data']) < 10000);
     $output = json_decode($result['data'], true);
     $this->assertEquals('Testing Message', $output['settings']['_subject']);
 }
 /**
  * Send mail
  *
  * @param \Cake\Mailer\Email $email Email
  * @return array
  */
 public function send(Email $email)
 {
     if (!empty($this->_config['queue'])) {
         $this->_config = $this->_config['queue'] + $this->_config;
         $email->config((array) $this->_config['queue'] + ['queue' => []]);
         unset($this->_config['queue']);
     }
     $settings = ['from' => [$email->from()], 'to' => [$email->to()], 'cc' => [$email->cc()], 'bcc' => [$email->bcc()], 'charset' => [$email->charset()], 'replyTo' => [$email->replyTo()], 'readReceipt' => [$email->readReceipt()], 'returnPath' => [$email->returnPath()], 'messageId' => [$email->messageId()], 'domain' => [$email->domain()], 'getHeaders' => [$email->getHeaders()], 'headerCharset' => [$email->headerCharset()], 'theme' => [$email->theme()], 'profile' => [$email->profile()], 'emailFormat' => [$email->emailFormat()], 'subject' => method_exists($email, 'getOriginalSubject') ? [$email->getOriginalSubject()] : [$email->subject()], 'transport' => [$this->_config['transport']], 'attachments' => [$email->attachments()], 'template' => $email->template(), 'viewVars' => [$email->viewVars()]];
     foreach ($settings as $setting => $value) {
         if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) {
             unset($settings[$setting]);
         }
     }
     $QueuedJobs = $this->getQueuedJobsModel();
     $result = $QueuedJobs->createJob('Email', ['settings' => $settings]);
     $result['headers'] = '';
     $result['message'] = '';
     return $result;
 }
Beispiel #5
0
 /**
  * Prepares the recipient email addresses.
  *
  * @param \Cake\Mailer\Email $email Email instance
  * @return array
  */
 protected function _prepareRecipientAddresses($email)
 {
     $to = $email->to();
     $cc = $email->cc();
     $bcc = $email->bcc();
     return array_merge(array_keys($to), array_keys($cc), array_keys($bcc));
 }
Beispiel #6
0
 /**
  * @param mixed $charset
  * @param mixed $headerCharset
  * @return \Cake\Mailer\Email
  */
 protected function _getEmailByNewStyleCharset($charset, $headerCharset)
 {
     $email = new Email(['transport' => 'debug']);
     if (!empty($charset)) {
         $email->charset($charset);
     }
     if (!empty($headerCharset)) {
         $email->headerCharset($headerCharset);
     }
     $email->from('*****@*****.**', 'どこかの誰か');
     $email->to('*****@*****.**', 'どこかのどなたか');
     $email->cc('*****@*****.**', 'ミク');
     $email->subject('テストメール');
     $email->send('テストメールの本文');
     return $email;
 }
Beispiel #7
0
 /**
  * testRcpt method
  *
  * @return void
  */
 public function testRcpt()
 {
     $email = new Email();
     $email->from('*****@*****.**', 'CakePHP Test');
     $email->to('*****@*****.**', 'CakePHP');
     $email->bcc('*****@*****.**');
     $email->cc(['*****@*****.**' => 'Mark Story', '*****@*****.**' => 'Juan Basso']);
     $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(6))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(9))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->socket->expects($this->at(12))->method('write')->with("RCPT TO:<*****@*****.**>\r\n");
     $this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false));
     $this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n"));
     $this->SmtpTransport->sendRcpt($email);
 }