-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] No default sender possible with sf messenger+ sf serializer #37414
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
Comments
This would be fixed by #37324 I guess. |
This will be fixed by #37847 |
@fabpot So it is intended that the message can no longer be modified in the MessageEvent triggered by the mailer before serialization, e.g. to set the sender or other details of the message in the context of the current request, which is lost when the message is later processed by the messenger? |
Yes, it is intended. The MessageEvent should not be triggered twice for a message. It is triggered just before the message is sent. |
Thanks for the clarification! |
The idea is that you always get the event just before sending the email and another one with the queued argument set to true when pushing to the queue. That allows to gather data for tests and the web profiler. |
…pot) This PR was merged into the 5.2-dev branch. Discussion ---------- [Serializer][Mime] Fix Mime message serialization | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | yes | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #37414, Fix #37324 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a Symfony serialization is used by Messenger to serialize Emails. By Email messages are data objects with some logic to prepare emails to be sent. Without configuration, the Symfony Serializer serializes Emails with too many data (and triggers some unneeded validation). This PR aims to fix the above issue and at the same time makes serialized emails as small as possible and as readable as possible. Commits ------- 9d869b1 Fix Mime message serialization
…on (fabpot) This PR was merged into the 5.2-dev branch. Discussion ---------- [Serializer][Mime] Fix Mime message serialization | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | yes | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix symfony#37414, Fix symfony#37324 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a Symfony serialization is used by Messenger to serialize Emails. By Email messages are data objects with some logic to prepare emails to be sent. Without configuration, the Symfony Serializer serializes Emails with too many data (and triggers some unneeded validation). This PR aims to fix the above issue and at the same time makes serialized emails as small as possible and as readable as possible. Commits ------- 9d869b1 Fix Mime message serialization
Symfony version(s) affected: 5.1, 5.2
Description
A MessageListener cannot be used to add a FROM header when the symfony/mailer is used together with symfony/messenger and symfony/serializer, a LogicException is thrown: An email must have a "From" or a "Sender" header.
How to reproduce
I'm sorry, at the moment I have no reproduce code.
Result: exception with 'An email must have a "From" or a "Sender" header.'
Possible Solution
Do not
clone $message
for the event in https://github.com/symfony/mailer/blob/master/Mailer.php#L48 to allow listeners to modify the message before serialization, they can check isQueued to prevent duplicate modification.Or, probably not that easy: Don't trigger ensureValidity() when the serializer calls getBody() on Symfony\Component\Mime\Email
Additional context
relevant part of the trace:
The normal flow in working cases is:
The problem occurs when the symfony serializer is used, which triggers the ensureValidity() method when the message is sent to the bus (see trace).
Because the listeners only receive a cloned message they cannot modify the real mail message object and thus cannot add a sender address.
This also effects PR #36736: The config options to set a default sender will not work because the mentioned exception is thrown because the included Symfony\Component\Mailer\EventListener\MessageListener will not be able to set headers because of the clone().
The text was updated successfully, but these errors were encountered: