/** * 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); }
/** * Send a mail message * * @param \Zend\Mail\Message $message * @return array */ public function send(Mail\Message $message) { $consumer = new Consumer(); $consumer->setUrl($this->config['url']); $params = array('to' => urlencode($this->config['to']), 'subject' => urlencode($message->getSubject()), 'from' => urlencode($message->getFrom()->current()->getEmail()), 'fromname' => urlencode($message->getFrom()->current()->getName()), 'text' => urlencode($message->getBodyText()), 'api_user' => urlencode($this->config['user']), 'api_key' => urlencode($this->config['key'])); $bcc = $message->getBcc()->current(); if ($bcc) { $params['bcc'] = $bcc->getEmail(); } $consumer->setParams($params); $consumer->setResponseType('json'); $consumer->setCallType('get'); return $consumer->doApiCall(); }
public function testRetrievingBodyTextFromMessageWithMultiPartMimeBodyReturnsMimeSerialization() { $mime = new Mime('foo-bar'); $text = new MimePart('foo'); $text->type = 'text/plain'; $html = new MimePart('<b>foo</b>'); $html->type = 'text/html'; $body = new MimeMessage(); $body->setMime($mime); $body->addPart($text); $body->addPart($html); $this->message->setBody($body); $text = $this->message->getBodyText(); $this->assertEquals($body->generateMessage(Headers::EOL), $text); $this->assertContains('--foo-bar', $text); $this->assertContains('--foo-bar--', $text); $this->assertContains('Content-Type: text/plain', $text); $this->assertContains('Content-Type: text/html', $text); }
public function getBodyText() { if (!$this->body) { $body = $this->getBody(); } return parent::getBodyText(); }
/** * Prepare body string from message * * @param Message $message * @return string */ protected function prepareBody(Message $message) { return $message->getBodyText(); }
/** * Prepare the body string * * @param \Zend\Mail\Message $message * @return string */ protected function prepareBody(Mail\Message $message) { if (!$this->isWindowsOs()) { // *nix platforms can simply return the body text return $message->getBodyText(); } // On windows, lines beginning with a full stop need to be fixed $text = $message->getBodyText(); $text = str_replace("\n.", "\n..", $text); return $text; }
/** * @param Message $message * @return bool */ public function send(Message $message) { $this->email->addTo($message->getTo()->current()->getEmail(), $message->getTo()->current()->getName())->setFrom($message->getFrom()->current()->getEmail(), $message->getFrom()->current()->getName())->setSubject($message->getSubject())->setHtml($message->getBodyText()); $this->sendGrid->send($this->email); return true; }
/** * Gets the raw MIME message text. * * @param Mail\Message $message * @return string */ private function getMessageText(Mail\Message $message) { return base64_encode($message->getHeaders()->toString() . Mail\Headers::EOL . $message->getBodyText()); }
/** * Gets the raw MIME message text. * * @param Mail\Message $message * @return string */ private function getMessageText(Mail\Message $message) { $raw = $message->getHeaders()->toString() . Mail\Headers::EOL . $message->getBodyText(); return $raw; }