You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TemplatedEmail are rendered two times: both the Mailer and the AbstractTransport class dispatch a MessageEvent.
The renderer (generally the BodyRenderer from TwigBridge) do not check if the email is already rendered and override the email contents (re-rendering the twig template).
How to reproduce
Send an email and check the event dispatcher logs, you can use a twig extension with a filter called inside the twig template to easily catch it.
Possible Solution
The render should check if the templated email is already rendered? Or maybe dispatch the email only one time?
Additional context
The text was updated successfully, but these errors were encountered:
This PR was merged into the 4.4 branch.
Discussion
----------
[TwigBridge] Render email once
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#39718
| License | MIT
| Doc PR | -
When `\Symfony\Component\Mailer\Mailer` send an email via the Bus (async) it dispatches an `MessageEvent`, then the consumer call the `\Symfony\Component\Mailer\Transport\AbstractTransport::send` method which also dispatches an `MessageEvent`.
This event is listened by `\Symfony\Bridge\Twig\Mime\BodyRenderer::render` which rendered twice an email.
I'm not sure why the event is send twice, and if we could safely remove one of them (or maybe deprecating the `MessageEvent`, in favor of `SendMessageEvent` + `AsyncMessageEvent`)
This PR store a flag in the Message to avoid rendering it twice.
Commits
-------
186ea59 Render email once
Symfony version(s) affected: 4.4.18
Description
TemplatedEmail are rendered two times: both the
Mailer
and theAbstractTransport
class dispatch a MessageEvent.The renderer (generally the
BodyRenderer
from TwigBridge) do not check if the email is already rendered and override the email contents (re-rendering the twig template).How to reproduce

Send an email and check the event dispatcher logs, you can use a twig extension with a filter called inside the twig template to easily catch it.
Possible Solution
The render should check if the templated email is already rendered? Or maybe dispatch the email only one time?
Additional context
The text was updated successfully, but these errors were encountered: