/** * {@inheritdoc} */ function buildNewsletterMail(array &$message, MailInterface $mail) { // Get message data from the mail. $message['headers'] = $mail->getHeaders($message['headers']); $message['subject'] = $mail->getSubject(); $message['body']['body'] = $mail->getBody(); $message['body']['footer'] = $mail->getFooter(); if ($mail->getFormat() == 'html') { // Set the necessary headers to detect this as an HTML mail. Set both the // Content-Type header, and the format (Swiftmailer) and plain (Mime Mail) // params. $message['headers']['Content-Type'] = 'text/html; charset=UTF-8'; $message['params']['format'] = 'text/html'; $message['params']['plain'] = NULL; // Provide a plain text version, both in params][plaintext (Mime Mail) and // plain (Swiftmailer). $message['params']['plaintext'] = $mail->getPlainBody() . "\n" . $mail->getPlainFooter(); $message['plain'] = $message['params']['plaintext']; // Add attachments, again, both for the attachments key (Mime Mail) and // files (Swiftmailer). $message['params']['attachments'] = $mail->getAttachments(); $message['params']['files'] = $message['params']['attachments']; } else { // This is a plain text email, explicitly mark it as such, the default // Content-Type header already defaults to that. $message['params']['plain'] = TRUE; $message['params']['format'] = 'text/plain'; } }
/** * {@inheritdoc} */ public function sendMail(MailInterface $mail) { $params['simplenews_mail'] = $mail; // Send mail. $message = $this->mailManager->mail('simplenews', $mail->getKey(), $mail->getRecipient(), $mail->getLanguage(), $params, $mail->getFromFormatted()); // Log sent result in watchdog. if ($this->config->get('mail.debug')) { if ($message['result']) { $this->logger->debug('Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to', array('%type' => $mail->getKey(), '%to' => $message['to'], '%subject' => $message['subject'])); } else { $this->logger->error('Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to', array('%type' => $mail->getKey(), '%to' => $message['to'], '%subject' => $message['subject'])); } } // Build array of sent results for spool table and reporting. if ($message['result']) { $result = array('status' => SpoolStorageInterface::STATUS_DONE, 'error' => FALSE); } else { // This error may be caused by faulty mailserver configuration or overload. // Mark "pending" to keep trying. $result = array('status' => SpoolStorageInterface::STATUS_PENDING, 'error' => TRUE); } return $result; }