jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
567 stars 129 forks source link

Plans to support symfony/mailer on this package #155

Closed abishekrsrikaanth closed 2 years ago

abishekrsrikaanth commented 2 years ago

@jdavidbakr

With Laravel 9 approaching soon, the swiftmailer/swiftmailer package is being removed and symfony/mailer will be used. Any plans to get this package ready with the release on the new Laravel version?

jdavidbakr commented 2 years ago

Going to have to wait on the 9.x-dev branch of Laravel, and orchestra/testbench to support Laravel 9.

leasify-it commented 2 years ago

Hurry up! :-)

jdavidbakr commented 2 years ago

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.

jdavidbakr commented 2 years ago

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?

tormjens commented 2 years ago

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');
});
jdavidbakr commented 2 years ago

Thanks - I will look at this as a possible solution!

jdavidbakr commented 2 years ago

I have the code updated, dependent on https://github.com/laravel/framework/pull/41615 being merged into 9.x

danpalmieri commented 2 years ago

Thanks @jdavidbakr and @tormjens ;-)

jdavidbakr commented 2 years ago

Released: https://github.com/jdavidbakr/mail-tracker/releases/tag/6.0