0

Im using Postmark to send emails in my Laravel 8 app. Im looking for a way to hook into the email notification (note: this is the Laravel notification, not mail message) to add Postmark tag.

Accoridng to the Laravel notification doc, Laravel fires some events before/after sending notificaiton but I cant figure out a way to access the mail object.

Here are my code:

class NewOrderNotification extends Notification implements ShouldQueue
{
    // ...

    public function via($notifiable)
    {
        return ['database', 'mail'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)->...
    }
}

Note: I need to be able to differentiate between emails sent using Notification vs emails sent using Mail Message. Because I want to add different tags on different emails. E.g. emails sent to purchasers -> tag with "receipt", emails sent to recipiennt -> tag with "order", and all notification emails -> tag with "notification".

Thanks.

Louis L
  • 81
  • 3
  • 9
  • The duplicate says event listener is the best way. The documentation you linked to only mentions the `MessageSent` event, but there's also a `MessageSending` event that has a `$message` property you can add headers to. – miken32 Nov 20 '20 at 03:54
  • See also here: https://laracasts.com/discuss/channels/laravel/how-to-add-custom-headers-to-notification-emails – miken32 Nov 20 '20 at 03:56

0 Answers0