Skip to content

[Mailer] Sendgrid API Transport: allow use of mail_settings #42915

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

Open
wants to merge 15 commits into
base: 7.4
Choose a base branch
from

Conversation

mikefox
Copy link

@mikefox mikefox commented Sep 7, 2021

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #42854
License MIT
Doc PR symfony/symfony-docs#...

The Sendgrid API allows filters to be sent via the mail_settings field when sending an email. This change allows users of the Sendgrid API mail transport to use this setting by setting a mail_settings text header on an email. This will be transformed into an array value that's sent as the mail_setting parameter.

@mikefox mikefox requested a review from chalasr as a code owner September 7, 2021 13:08
@carsonbot carsonbot changed the title [MAILER] Sendgrid API Transport: allow use of mail_settings [Mailer] Sendgrid API Transport: allow use of mail_settings Sep 7, 2021
@mikefox mikefox force-pushed the mailer-sendgrid-api-transport-allow-mail-settings branch 2 times, most recently from 6f80065 to 5634789 Compare September 7, 2021 13:17
@carsonbot
Copy link

Hey!

I think @versgui has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@nicolas-grekas nicolas-grekas added this to the 5.4 milestone Sep 17, 2021
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Passing this as a fake header is a bit hacky I suppose, but I don't have a better idea. Can you please add some test cases? And can you also please send a PR for the doc?

@fabpot
Copy link
Member

fabpot commented Sep 19, 2021

I'm also not a big fan of using a fake header. In any case, we don't add specific features of providers as we want devs to be able to switch from one provider to another one. But if this feature could be added to many providers, then, let's think about a proper way to support it. But the first step is to really understand if this can be supported by more than just Sendgrid.

@mikefox
Copy link
Author

mikefox commented Sep 20, 2021

@fabpot @nicolas-grekas I think a less hacky version would require adding a new optional property to the Symfony\Component\Mime\Message class that allows you to set provider-specific instructions that can be used in the provider's transport class. If you agree I can put something together in this PR.

@mikefox mikefox force-pushed the mailer-sendgrid-api-transport-allow-mail-settings branch from 8cf95ef to 80e4083 Compare September 20, 2021 08:37
@mikefox mikefox force-pushed the mailer-sendgrid-api-transport-allow-mail-settings branch from 80e4083 to 54e8c9c Compare October 8, 2021 16:49
@mikefox
Copy link
Author

mikefox commented Oct 8, 2021

A better solution that's extensible for other transport providers.

@mikefox
Copy link
Author

mikefox commented Oct 20, 2021

@fabian @nicolas-grekas any thoughts on this?

@fabpot
Copy link
Member

fabpot commented Oct 20, 2021

I'm still not sure this is something we want to support. In any case, this is probably not something that can be part of the Envelope.

@fabpot fabpot modified the milestones: 5.4, 6.1 Nov 3, 2021
@mikefox mikefox force-pushed the mailer-sendgrid-api-transport-allow-mail-settings branch from 4b7cd65 to c009262 Compare December 2, 2021 10:03
@mikefox
Copy link
Author

mikefox commented Dec 2, 2021

@nicolas-grekas Thanks for your comments, I've addressed your feedback.

@mikefox mikefox requested a review from nicolas-grekas January 4, 2022 09:07
@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@MaximePinot
Copy link
Contributor

MaximePinot commented Jul 5, 2022

Friendly ping @nicolas-grekas and @fabpot. What do you think of @mikefox's implementation?

I can help with this PR. I would also like to be able to use the mail_settings field.

EDIT: Eventually did it with a decorated HttpClient and a CompilerPass: https://gist.github.com/MaximePinot/85ef21d21f06ada31c097709769eb084

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Here are some comments. This PR is related to #41714
@fabpot I think we need to figure out a way for Mailer to support those features. Eg templates: I don't think we can abstract them in the component, but support for them looks desired. The code is almost capable of doing it. Can we reconsider the rejection of such changes, as done in #41714?

@@ -1,6 +1,12 @@
CHANGELOG
=========

6.1
Copy link
Member

Choose a reason for hiding this comment

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

6.2 now

6.1
---

* Check the `Envelope` options for a "mail_settings" property and send the
Copy link
Member

Choose a reason for hiding this comment

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

missing space at head of line
the description is misleading I think: the code doesn't check for mail_settings anywhere

@@ -145,6 +145,10 @@ private function getPayload(Email $email, Envelope $envelope): array
$personalization['custom_args'] = $customArguments;
}

foreach ($envelope->getOptions() as $name => $value) {
$payload[$name] = $value;
Copy link
Member

Choose a reason for hiding this comment

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

This allows overriding any pre-existing payload key. This might be too risky.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do this instead?

Suggested change
$payload[$name] = $value;
if (!array_key_exists($name, $payload) {
$payload[$name] = $value;
}

@@ -1,6 +1,11 @@
CHANGELOG
=========

6.1
Copy link
Member

Choose a reason for hiding this comment

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

6.2

6.1
---

* Added the `options` property to `Envelope`
Copy link
Member

Choose a reason for hiding this comment

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

missing space

@MaximePinot MaximePinot force-pushed the mailer-sendgrid-api-transport-allow-mail-settings branch from 568a523 to 21063b6 Compare July 9, 2022 10:06
@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
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.

[Mailer] SendGrid bypass suppressions
6 participants