Ejemplo n.º 1
0
 /**
  * Send a mail message
  *
  * @param Mail\Message $message
  * @return array
  */
 public function send(Mail\Message $message)
 {
     $this->getMandrillClient();
     $body = $message->getBody();
     $attachments = [];
     switch (true) {
         case $body instanceof Message:
             $bodyHtml = $this->getHtmlPart($body);
             $bodyText = $this->getTextPart($body);
             $attachments = $this->getAttachments($body);
             break;
         case is_string($body):
             $bodyHtml = $body;
             $bodyText = $message->getBodyText();
             break;
         case is_object($body):
             $bodyHtml = $body->__toString();
             $bodyText = $message->getBodyText();
             break;
         default:
             throw new Exception\InvalidArgumentException(sprintf('"%s" expectes a body that is a string, an object or a Zend\\Mime\\Message; received "%s"', __METHOD__, is_object($body) ? get_class($body) : gettype($body)));
             break;
     }
     $message = ['html' => $bodyHtml, 'text' => $bodyText, 'subject' => $message->getSubject(), 'from_email' => $message->getFrom()->current()->getEmail(), 'from_name' => $message->getFrom()->current()->getName(), 'to' => array_merge($this->mapAddressListToArray($message->getTo(), 'to'), $this->mapAddressListToArray($message->getCc(), 'cc'), $this->mapAddressListToArray($message->getBcc(), 'bcc')), 'headers' => $message->getHeaders()->toArray(), 'subaccount' => $this->options->getSubAccount(), 'attachments' => $attachments];
     return $this->mandrillClient->messages->send($message);
 }
Ejemplo n.º 2
0
 public function testSetSubAccount()
 {
     $this->mandrillOptions->setSubAccount('another-subaccount');
     $this->assertEquals('another-subaccount', $this->mandrillOptions->getSubAccount());
 }