Skip to content

[Mailer] Implement EmailTags for Amazon Mailer #45222

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

Merged
merged 1 commit into from
Feb 2, 2022
Merged

[Mailer] Implement EmailTags for Amazon Mailer #45222

merged 1 commit into from
Feb 2, 2022

Conversation

driesvints
Copy link
Contributor

@driesvints driesvints commented Jan 28, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR

This PR implements support for X-SES-MESSAGE-TAGS headers with the Amazon Mailer. See example of this here: https://docs.aws.amazon.com/ses/latest/dg/event-publishing-send-email.html

I'm sending this in because atm we can't provide support for this in Laravel 9 after switching to Symfony Mailer. Since the transports are completely closed from adding additional headers before sending them to the SendEmailRequest class, the only way to add this is by adding it directly in the transports.

I tried my best with writing a function that'll parse the header and prep the array to be sent to the SendEmailRequest class.

Ideally, it would be great if this could be added to 6.0 as well because Symfony 6.1 is due to be released in May while Laravel 9 is being released in less than two weeks. But, we can always re-implement our old SesTransport (something I'm going to prep regardless so that's ready to go if this can't be back ported to 6.0).

I haven't sent in a PR to the docs because there aren't any docs yet for other X-SES- headers.

Thanks!

PS.: Because I used the GH CLI to send this in I didn't see the PR template. Therefor @carsonbot already added all these labels and I can't remove them anymore.

$tag = explode('=', trim($tag), 2);

return ['Name' => $tag[0], 'Value' => $tag[1]];
}, explode(',', $tags));
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we care about escaping?

ie. handling keys/values with special chars like = or ,?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would you approach this?

@driesvints
Copy link
Contributor Author

Not sure why Psalm fails because a type check for the correct type is done right before the place it notes an incompatible type.

@norkunas
Copy link
Contributor

Maybe would be better to use Symfony\Component\Mailer\Header\TagHeader as in other transports?

@driesvints
Copy link
Contributor Author

driesvints commented Jan 28, 2022

@norkunas hmm maybe yeah but I'm a bit unfamiliar with. Also, it seems from the AWS docs that it keeps all values in a single value. It would solve the issue with escaping which @jderusse explains though.

@norkunas
Copy link
Contributor

Each transport can serialize tags how it needs, so using that header the tags would also work when switching transports

@carsonbot carsonbot changed the title Implement EmailTags for Amazon Mailer [Mailer] Implement EmailTags for Amazon Mailer Jan 29, 2022
@driesvints
Copy link
Contributor Author

Hey all, we decided to restore our old custom SesTransport for Laravel 9. I'll leave this PR in draft for now until I can finish it up with the suggestion from @norkunas. If anyone wants to steal the code to get this in sooner feel free to 👍

@kbond
Copy link
Member

kbond commented Feb 1, 2022

We'll definitely want to use TagHeader MetadataHeader here.

@kbond kbond marked this pull request as ready for review February 1, 2022 23:27
@kbond
Copy link
Member

kbond commented Feb 1, 2022

Hey @driesvints, I took the liberty to complete this PR using the MetadataHeader. Amazon calls these tags but in Symfony, they would be considered "metadata" as these "tags" have a key and a value.

This doc section describes the usage of MetadataHeader. Many transports support tags/metadata. Could be an interesting feature to add to Laravel's mailables/notifications.

@fabpot
Copy link
Member

fabpot commented Feb 2, 2022

Thank you @driesvints.

@fabpot fabpot merged commit 1e54965 into symfony:6.1 Feb 2, 2022
@driesvints driesvints deleted the additional-ses-features branch February 3, 2022 09:50
@driesvints
Copy link
Contributor Author

Oh wauw, thanks for taking that over @kbond, that looks really good! 🙂 👍

@fabpot fabpot mentioned this pull request Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants