Skip to content

[9.x] Add mailer name to data for SentMessage and MessageSending events#46079

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
colq2:9.x
Feb 11, 2023
Merged

[9.x] Add mailer name to data for SentMessage and MessageSending events#46079
taylorotwell merged 2 commits into
laravel:9.xfrom
colq2:9.x

Conversation

@colq2

@colq2 colq2 commented Feb 10, 2023

Copy link
Copy Markdown
Contributor

This PR adds the mailer name to data for the MessageSending and SentMessage events.

It is impossible to detect through which mailer a mailable is sent when listening to the MessageSending and SentMessage event.

There are some use cases where this is a benefit:

  1. Stop sending the email depending on the mailer.

  2. Storin outgoing mail with its mailer (from a package)

When using different mailers and a custom failover logic, it is important to know from which mailer a message was sent. Especially when using a package and the only way to intercept mails are the events.

Accessing the mailer from event data looks like this:

Event::listen(MessageSending::class, function(MessageSending $event){
    $mailer = $event->data['mailer'];
});

@taylorotwell taylorotwell merged commit dd3abef into laravel:9.x Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants