Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Mailer] [Sendgrid] Add template support#41714
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[Mailer] [Sendgrid] Add template support#41714
Uh oh!
There was an error while loading.Please reload this page.
Conversation
src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
I'm not sure we want to add this to the component. The code you write is strongly tied to the Sendgrid mailer and would break when using another transport. |
What do you mean, I only set headers on a mime email, so it would not break with other transports. The headers are then only interpreted by the SendgridApiTransport 🤷♂️ |
@OskarStark but the code you wrote in your PR description would not work if you configure the mailer with another transport (it would send an email with |
OskarStark commentedJun 15, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
In this case documenting it and tell the people to write valid text and html content as fallback?
Another case about headers, if I can set symfony/src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php Lines 106 to 112 in4a0c4e3
|
What about adding $email->setNoContent(true) to explicitly mark this email without content? |
but if they write the HTML and text body in their app, there is no point using a sendgrid template managing that content on sendgrid (it might even be worse if they get out of sync)
that would still make your code work properly only with the SendgridTransport, by adding features in that transport that bypass the component abstraction. |
I agree
But it would make clear to the developer that it can be used across transports but without content IF the other transport does not understand that header. I mean what would be the solution? Our Mailer cannot support such things? Abstractions are nice, but always limit the power to the lowest feature set 🤷 Thats why I wanted to work around this limitation using a common way of dealing with custom things: headers. |
@OskarStark to me, email templates are not something you can abstract easily. Some provider maintain templates in their own system with a parameter in the API call (as done by Sendgrid) or with a separate API endpoint. Others are using the email body as template source, with a different syntax each for the templating language. And some of the features of the components are also incompatible with that (using the DkimSigner on an email which will have its content replaced on the provider server when applying the template won't work for instance). |
I agree, this is just my first idea on how to implement it. Any advice how this can be done? I am open for ideas to extend the Symfony mailer ecosystem this way. |
OskarStark commentedJun 16, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Btw. isn't this the same problem we currently have with symfony/src/Symfony/Component/Notifier/Bridge/Telegram/TelegramTransport.php Lines 61 to 72 inf12a419
And if we would remove the options check we would only send the plain message via another transport, but additional tied information, which are located in the options, would be ignored by another transport. |
As I mentioned in some other issues/PRs, I'm against supporting specific features of each mailer. The main goal of the component is to be able to switch from one provider to another one or been mix them (round-robin). If we find an abstraction that would work for the vast majority of the current providers, why not, but having specific features is a no-go for me. |
Fine, but we currently do the same thing with options, if I add some kind of Options to a ChatMessage, I cannot use it with any other transport. |
Uh oh!
There was an error while loading.Please reload this page.
Documentation:https://sendgrid.com/docs/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates/#send-a-transactional-email
You can now do the following:
I am however not sure about the
json_encode
/json_decode
for handling an array, any proposal?I also tried to use sth. like:
but I am not sure about the spec and if I am allowed to add a new kind of header to the Mime component 🤔
Note that you need to add sth. like:
otherwise you will receive an exception:
