Merge pull request #14975 from owncloud/add-smtp-debug-mode

Add debug mode back to mailer
This commit is contained in:
Thomas Müller 2015-03-17 23:49:19 +01:00
commit a4d2c7810e
1 changed files with 16 additions and 1 deletions

View File

@ -73,15 +73,30 @@ class Mailer implements IMailer {
* has been supplied.) * has been supplied.)
*/ */
public function send(Message $message) { public function send(Message $message) {
$debugMode = $this->config->getSystemValue('mail_smtpdebug', false);
if (sizeof($message->getFrom()) === 0) { if (sizeof($message->getFrom()) === 0) {
$message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName())]); $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName())]);
} }
$failedRecipients = []; $failedRecipients = [];
$this->getInstance()->send($message->getSwiftMessage(), $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()); $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject());
$this->logger->debug($logMessage, ['app' => 'core']); $this->logger->debug($logMessage, ['app' => 'core']);
if($debugMode && isset($mailLogger)) {
$this->logger->debug($mailLogger->dump(), ['app' => 'core']);
}
return $failedRecipients; return $failedRecipients;
} }