public function withEmailFound()
 {
     $email = new EmailEntity();
     $email->exchangeArray(['id' => 'emailId']);
     $this->mockEmailMapper->expects($this->once())->method('findById')->with($this->equalTo('emailId'))->will($this->returnValue($email));
     return $email;
 }
Example #2
0
 /**
  * Build Mandrill compatible message array from email entity
  *
  * Documentation at https://mandrillapp.com/api/docs/messages.php.html
  *
  * @param  EmailEntity  $emails
  * @return array
  */
 protected function buildMessage(EmailEntity $email)
 {
     // Create attachments array
     $attachments = json_decode($email->getAttachments(), true);
     $recipientEmail = $email->getRecipientEmail();
     $to = [['email' => $this->filterThroughWhitelist($recipientEmail), 'name' => $email->getRecipientName(), 'type' => 'to']];
     $message = ['html' => $email->getMessage(), 'subject' => $email->getSubject(), 'from_email' => $email->getSenderEmail(), 'from_name' => $email->getSenderName(), 'to' => $to, 'attachments' => $attachments, 'headers' => json_decode($email->getHeaders(), true), 'important' => false, 'track_opens' => true, 'track_clicks' => true, 'auto_text' => true, 'auto_html' => false, 'inline_css' => true, 'url_strip_qs' => null, 'preserve_recipients' => false, 'bcc_address' => $email->getBcc(), 'merge' => true];
     return $message;
 }
 public function expectingEmailCreatedFromArray()
 {
     $captured = new \stdClass();
     $this->mockEmailService->expects($this->once())->method('createFromArray')->will($this->returnCallback(function ($array) use($captured) {
         $captured->emailArray = $array;
         $email = new EmailEntity();
         $email->exchangeArray($array);
         $captured->createdEmailEntity = $email;
         return $email;
     }));
     return $captured;
 }
 /**
  * Build Mailgun compatible message array from email entity
  *
  * Documentation at https://mandrillapp.com/api/docs/messages.php.html
  *
  * @param  EmailEntity  $emails
  * @return array
  */
 protected function buildMessage(EmailEntity $email)
 {
     // Create attachments array
     $attachments = json_decode($email->getAttachments(), true) ?: [];
     // Convert Mandrill format to Mailgun format
     $attachments = array_map(function ($attachment) {
         if (isset($attachment['content'])) {
             $attachment['data'] = base64_decode(Arr::remove($attachment, 'content'));
         }
         if (isset($attachment['name'])) {
             $attachment['filename'] = Arr::remove($attachment, 'name');
         }
         if (isset($attachment['type'])) {
             $attachment['contentType'] = Arr::remove($attachment, 'type');
         }
         return attachment;
     }, $attachments);
     if ($email->getSenderName()) {
         $from = "{$email->getSenderName()} <{$email->getSenderEmail()}>";
     } else {
         $from = $email->getSenderEmail();
     }
     if ($email->getTemplateName()) {
         $html = $this->templateService->renderHbsForEmail($email->getTemplateName(), $email->getTemplateData() ? json_decode($email->getTemplateData(), true) : []);
     } else {
         $html = $email->getMessage();
     }
     $message = ['html' => $html, 'subject' => $email->getSubject(), 'from' => $from, 'to' => $this->filterThroughWhitelist($email->getRecipientEmail()), 'attachments' => $attachments];
     if ($email->getHeaders()) {
         $headers = [];
         foreach (json_decode($email->getHeaders(), true) as $key => $value) {
             $headers["h:{$key}"] = $value;
         }
         $message['headers'] = $headers;
     }
     return $message;
 }
Example #5
0
 /**
  * Queue a job to send an email
  *
  * @param  EmailEntity $email
  * @return string
  */
 public function enqueueSendEmailJob(EmailEntity $email)
 {
     return $this->resque->enqueue('email', 'Synapse\\Work\\Email\\Send', ['id' => $email->getId()]);
 }