Closed abishekrsrikaanth closed 2 years ago
Going to have to wait on the 9.x-dev branch of Laravel, and orchestra/testbench to support Laravel 9.
Hurry up! :-)
I've been swamped and haven't had a chance to investigate what needs to happen to change to use symfony/mailer instead of swiftmailer/swiftmailer. If someone wants to investigate and submit a pull request I will be happy to accept it, otherwise I will get this updated once I have some time to do so.
Folks, I'm going to need some help from someone who knows a bit more about the Symfony Mailer. After digging for quite a while I don't see a way to hook in to modify the outgoing email the way you could with the SwiftMailer. Anyone want to at least pass some knowledge about how I can keep this package alive?
I've done some digging here, and it seems listening to both before sending and after sending is possible. The Laravel Mailer dispatches two events during sending; MessageSent
and MessageSending
.
Listening to the MessageSending
event will allow you to modify the outgoing message and you can access the underlying Symfony\Component\Mime\Email
which will allow you to add your own headers etc.
Here's some code I used while tinkering with this. Hopefully this can't help point you in some kind of direction. How this would translate to what you did with SwiftMailer, I'm not sure, but hopefully it is to some help.
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Mail\Events\MessageSent;
use Illuminate\Mail\Events\MessageSending;
Event::listen(MessageSent::class, function($mail) {
dd($mail->message->getHeaders());
});
Event::listen(MessageSending::class, function($mail) {
$mail->message->getHeaders()->addTextHeader('X-Modified', 'Foo Mod');
});
Mail::raw('Foo bar!', function ($message) {
$message->to('some@thing.com')
->subject('Test');
});
Thanks - I will look at this as a possible solution!
I have the code updated, dependent on https://github.com/laravel/framework/pull/41615 being merged into 9.x
Thanks @jdavidbakr and @tormjens ;-)
@jdavidbakr
With Laravel 9 approaching soon, the
swiftmailer/swiftmailer
package is being removed andsymfony/mailer
will be used. Any plans to get this package ready with the release on the new Laravel version?