admin管理员组文章数量:1355665
We are looking for a code snipped to test a Laravel mail SMTP while printing out the SMTP dialog. The SMTP dialog usually contains the message ID, so in case a mail does not reach it can be traced on the involved server.
In previous Laravel versions we used
$to = '[email protected]';
Mail::getSwiftMailer()->registerPlugin( new Swift_Plugins_LoggerPlugin( new Swift_Plugins_Loggers_EchoLogger(false) ));
Mail::raw('Testmail', function ($message) use ($to) { $message->to($to)->subject('Testmail'); });
This leads to
BadMethodCallException Method Illuminate\Mail\Mailer::getSwiftMailer does not exist.
How can this be ported to Laravel 11 which uses Symfony mailer?
Tried a bit with ChatGPT but no luck so far.
We are looking for a code snipped to test a Laravel mail SMTP while printing out the SMTP dialog. The SMTP dialog usually contains the message ID, so in case a mail does not reach it can be traced on the involved server.
In previous Laravel versions we used
$to = '[email protected]';
Mail::getSwiftMailer()->registerPlugin( new Swift_Plugins_LoggerPlugin( new Swift_Plugins_Loggers_EchoLogger(false) ));
Mail::raw('Testmail', function ($message) use ($to) { $message->to($to)->subject('Testmail'); });
This leads to
BadMethodCallException Method Illuminate\Mail\Mailer::getSwiftMailer does not exist.
How can this be ported to Laravel 11 which uses Symfony mailer?
Tried a bit with ChatGPT but no luck so far.
Share Improve this question edited Mar 28 at 9:57 Alex asked Mar 28 at 9:43 AlexAlex 35.3k19 gold badges114 silver badges197 bronze badges 4 |2 Answers
Reset to default 2Based on Nico's answer, I came up with the following snipped which can easily be pasted to php artisan tinker
to debug mail delivery of a Laravel 9+ appication:
$to = '[email protected]';
\Illuminate\Support\Facades\Event::listen(function (\Illuminate\Mail\Events\MessageSent $event) {
echo "Message-ID\n";
echo $event->sent->getSymfonySentMessage()->getMessageId() . "\n";
echo "SMTP Dialog:\n";
echo $event->sent->getSymfonySentMessage()->getDebug() . "\n";
});
\Illuminate\Support\Facades\Mail::raw('Testmail', function ($message) use ($to) {
$message->to($to)->subject('Testmail ' . date('Y-m-d H:i:s'));
});
You can simply achieve that with symfony/mailer
: Write an event handler that listens for SentMessageEvent
. It contains an object of SentMessage
, and its property debug
contains the full smtp dialog.
本文标签: symfonyDebug Laravel Mail Sending in Laravel 11 including SMTP DialogStack Overflow
版权声明:本文标题:symfony - Debug Laravel Mail Sending in Laravel 11 including SMTP Dialog - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744045478a2581440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
getDebug()
from theSendMessage
object has to offer? – Nico Haase Commented Mar 28 at 10:02