Skip to content

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('[email protected]', 'Example')
                ->tag('shipment')
                ->metadata('order_id', $this->order->id)
                ->view('emails.orders.shipped');
}

// in your notification:
public function toMail($notifiable)
{
    return (new MailMessage)
                ->from('[email protected]', '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.

3 participants