Commit 3838b501 by Carsten Brandt

refactored Debug Mail panel to work with different vendors

implementation checks for instanceof for additional swiftmailer capabilities. issue #2870
parent 4c09aef2
...@@ -38,6 +38,11 @@ td, th { ...@@ -38,6 +38,11 @@ td, th {
word-break: break-all; word-break: break-all;
} }
.not-set {
color: #c55;
font-style: italic;
}
.detail-grid-view th { .detail-grid-view th {
white-space: nowrap; white-space: nowrap;
} }
......
...@@ -13,6 +13,7 @@ use yii\debug\models\search\Mail; ...@@ -13,6 +13,7 @@ use yii\debug\models\search\Mail;
use yii\debug\Panel; use yii\debug\Panel;
use yii\mail\BaseMailer; use yii\mail\BaseMailer;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
use yii\mail\MessageInterface;
/** /**
* Debugger panel that collects and displays the generated emails. * Debugger panel that collects and displays the generated emails.
...@@ -39,27 +40,37 @@ class MailPanel extends Panel ...@@ -39,27 +40,37 @@ class MailPanel extends Panel
parent::init(); parent::init();
Event::on(BaseMailer::className(), BaseMailer::EVENT_AFTER_SEND, function ($event) { Event::on(BaseMailer::className(), BaseMailer::EVENT_AFTER_SEND, function ($event) {
$message = $event->message->getSwiftMessage(); /** @var MessageInterface $message */
$textBody = $message->getBody(); $message = $event->message;
$fileName = $event->sender->generateMessageFileName(); $messageData = [
FileHelper::createDirectory(Yii::getAlias($this->mailPath));
file_put_contents(Yii::getAlias($this->mailPath) . '/' . $fileName, $message->toString());
$this->_messages[] = [
'isSuccessful' => $event->isSuccessful, 'isSuccessful' => $event->isSuccessful,
'time' => $message->getDate(),
'headers' => $message->getHeaders(),
'from' => $this->convertParams($message->getFrom()), 'from' => $this->convertParams($message->getFrom()),
'to' => $this->convertParams($message->getTo()), 'to' => $this->convertParams($message->getTo()),
'reply' => $this->convertParams($message->getReplyTo()), 'reply' => $this->convertParams($message->getReplyTo()),
'cc' => $this->convertParams($message->getCc()), 'cc' => $this->convertParams($message->getCc()),
'bcc' => $this->convertParams($message->getBcc()), 'bcc' => $this->convertParams($message->getBcc()),
'subject' => $message->getSubject(), 'subject' => $message->getSubject(),
'body' => $textBody,
'charset' => $message->getCharset(), 'charset' => $message->getCharset(),
'file' => $fileName,
]; ];
// add more information when message is a SwiftMailer message
if ($message instanceof \yii\swiftmailer\Message) {
/** @var \Swift_Message $swiftMessage */
$swiftMessage = $message->getSwiftMessage();
$messageData['body'] = $swiftMessage->getBody();
$messageData['time'] = $swiftMessage->getDate();
$messageData['headers'] = $swiftMessage->getHeaders();
}
// store message as file
$fileName = $event->sender->generateMessageFileName();
FileHelper::createDirectory(Yii::getAlias($this->mailPath));
file_put_contents(Yii::getAlias($this->mailPath) . '/' . $fileName, $message->toString());
$messageData['file'] = $fileName;
$this->_messages[] = $messageData;
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment