/** * {@inheritdoc} */ protected function getFiles(MessageInterface $message) { if (!$message instanceof AttachmentsAwareInterface) { return array(); } // Process files list($attachments, $inline) = $this->processAttachments($message->getAttachments()); // Format params $files = array(); if ($attachments) { $files['attachment'] = $attachments; } if ($inline) { $files['inline'] = $inline; } return $files; }
/** * {@inheritdoc} */ protected function format(MessageInterface $message) { $headers = array(); foreach ($message->getHeaders() as $name => $value) { $headers[] = array('Name' => $name, 'Value' => $value); } $parameters = array('From' => $this->buildIdentityString($message->getFrom()), 'To' => $this->buildIdentityString($message->getTo()), 'Subject' => $message->getSubject(), 'Headers' => $headers, 'HtmlBody' => $message->getHtml(), 'TextBody' => $message->getText(), 'ReplyTo' => $message->getReplyTo()); if ($message instanceof TaggableInterface) { $tag = $message->getTag(); if (is_array($tag)) { $tag = reset($tag); } $parameters['Tag'] = $tag; } if ($message instanceof AttachmentsAwareInterface) { $attachments = $this->processAttachments($message->getAttachments()); if ($attachments) { $parameters['Attachments'] = $attachments; } } return json_encode(array_filter($parameters)); }
/** * {@inheritdoc} */ protected function format(MessageInterface $message) { // We should split up the ServerToken on : to get username and password list($username, $password) = explode(':', $this->getServerToken()); $from = $this->normalizeIdentity($message->getFrom()); $toEmails = array(); $toNames = array(); foreach ($this->normalizeIdentities($message->getTo()) as $recipient) { $toEmails[] = $recipient->getEmail(); $toNames[] = $recipient->getName(); } $bccEmails = array(); foreach ($this->normalizeIdentities($message->getBcc()) as $recipient) { $bccEmails[] = $recipient->getEmail(); } $smtpApi = array(); if ($message instanceof TaggableInterface) { $smtpApi['category'] = (array) $message->getTag(); } if ($message instanceof MetadataAwareInterface) { $smtpApi['unique_args'] = array_filter($message->getMetadata()); } $inline = array(); if ($message instanceof AttachmentsAwareInterface) { // Store inline attachment references list(, $inline) = $this->processAttachments($message->getAttachments()); } $parameters = array('api_user' => $username, 'api_key' => $password, 'to' => $toEmails, 'toname' => $toNames, 'from' => $from->getEmail(), 'fromname' => $from->getName(), 'subject' => $message->getSubject(), 'text' => $message->getText(), 'html' => $message->getHtml(), 'bcc' => $bccEmails, 'replyto' => $message->getReplyTo(), 'headers' => json_encode($message->getHeaders()), 'content' => $inline); if ($smtpApi) { $parameters['x-smtpapi'] = json_encode(array_filter($smtpApi)); } return http_build_query(array_filter($parameters)); }