public function testSetHtmlBody() { $this->swiftMessage ->expects($this->once()) ->method('addPart') ->with('<blink>Fancy Body</blink>', 'text/html'); $this->message->setHtmlBody('<blink>Fancy Body</blink>'); }
/** * Send the specified message. Also sets the from address to the value defined in config.php * if no-one has been passed. * * @param Message $message Message to send * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and * therefore should be considered * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address * has been supplied.) */ public function send(Message $message) { $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); if (sizeof($message->getFrom()) === 0) { $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName())]); } $failedRecipients = []; $mailer = $this->getInstance(); // Enable logger if debug mode is enabled if ($debugMode) { $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); } $mailer->send($message->getSwiftMessage(), $failedRecipients); // Debugging logging $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); $this->logger->debug($logMessage, ['app' => 'core']); if ($debugMode && isset($mailLogger)) { $this->logger->debug($mailLogger->dump(), ['app' => 'core']); } return $failedRecipients; }