Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] ability to add tags/metadata to Emails/Notifications #40783

Merged
merged 3 commits into from
Feb 4, 2022

Conversation

kbond
Copy link
Contributor

@kbond kbond commented Feb 3, 2022

symfony/mailer has a special TagHeader and MetadataHeader for adding tags/metadata to emails in a generic way. All the transports/drivers you document support these with the slight exception of SES: it doesn't have tags in the way Symfony defines them but does have metadata. SES calls these tags so it's a bit confusing. Symfony's SES transport will support metadata in 6.1 but I see you created your own SESTransport. I can add support to your transport if desired.

Here's how tags and metadata are used with Postmark - all services are similar I believe.

I thought it would be nice to have helpers to add this data in Mailable/MailMessage:

// in your mailable:
public function build()
{
    return $this->from('example@example.com', 'Example')
                ->tag('shipment')
                ->metadata('order_id', $this->order->id)
                ->view('emails.orders.shipped');
}

// in your notification:
public function toMail($notifiable)
{
    return (new MailMessage)
                ->from('barrett@example.com', 'Barrett Blair')
                ->tag('upvote')
                ->metadata('comment_id', $this->comment->id)
                ->line('...');
}

If this is of interest, I can add tests/docs. Maybe you'd want the methods in a trait or done a different way - let me know!

Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks @kbond!

@driesvints
Copy link
Member

@taylorotwell I think this could indeed be useful for people now that we're integrating directly with Symfony Mailer.

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.

None yet

3 participants