Open
Description
Symfony version(s) affected: symfony/mailer: 4.3.4
Description
Sending Messages Async with json serializer does not work with SendEmailMessage.
Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException : Cannot create an instance of Symfony\Component\Mime\RawMessage from serialized data because its constructor requires parameter "message" to be present.
/home/vagrant/www/fxbackoffice.local/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php:505
...
How to reproduce
framework:
messenger:
serializer:
default_serializer: messenger.transport.symfony_serializer
symfony_serializer:
format: json
transports:
async: "%env(MESSENGER_TRANSPORT_DSN)%"
routing:
'Symfony\Component\Mailer\Messenger\SendEmailMessage': async
Activity
[-][Mailer] [/-][+][Mailer] Sending Messages Async with json serializer does not work[/+]danielchodusov commentedon Sep 13, 2019
Iam having the same issue. Sending message async doesn't work. On serialization I recive " A message must have a text or an HTML part or attachments."
mlojewski commentedon Nov 7, 2019
Check if your symfony/twig-bundle is in 4.3 version - helped for me
Mrkisha commentedon Dec 13, 2019
Having exact same problem, and have
symfony/twig-bundle:4.4
.xabbuh commentedon Dec 14, 2019
Can any of you create a small example application that allows to reproduce the issue?
diabl0 commentedon Dec 20, 2019
Sample app showing error: https://github.com/diabl0/async-mailer
Nyholm commentedon Jan 26, 2020
I can confirm this issue.
It happens because we cannot normalize
RawMessage
from Mime component. It has a constructor with required arguments.We need to use a serializer with the
PropertyNormalizer
normalizer, then everything will be fine. Im not sure whyPropertyNormalizer
is not configured by default though...wtorsi commentedon Jan 28, 2020
Actually, i've already written about this bug to fabpot, about 6 months ago i hope, but I can't find it now, so i can't say what he said about this problem.
In my app I'm using
Mailer
in another already async handler.For quick fix, my decision was to create custom
Mailer
(thx to container), to exclude redundant de/normalization.32 remaining items
mabumusa1 commentedon Apr 5, 2022
@florentdestremau I support your change, we need to use JSON instead of php-serialization
mabumusa1 commentedon May 31, 2022
@florentdestremau please make a PR, I will review it and hopefully, we can get it merged. This is important feature
florentdestremau commentedon May 31, 2022
I have no idea what is needed so unless a contributor is willing to point out the direction, this isn't going anywhere for now
RCheesley commentedon Jul 21, 2022
@Nyholm is there any chance of getting some guidance on this issue? It's blocking a pretty major PR we need to integrate in our next major release of Mautic to switch from Swiftmailer to Symfony Mailer but folks don't seem to be clear on how to proceed.
fabpot commentedon Jul 27, 2022
IIUC, there is no issue to fix in Symfony Mailer, but it's more about the inability to serialize an email to JSON via the Symfony serializer.
Wirone commentedon Jul 27, 2022
@fabpot I don't know if you're familiar with my comment but IMHO there was architectural issue in Mailer/Mime component. I said "was" because I don't use Messenger/Mailer currently and I don't know state of the codebase. But looking at
SendEmailMessage
at 6.2 it looks like issue remains.kor3k commentedon Jan 12, 2023
what about widening
SendEmailMessage::$message
andSendEmailMessage::__construct($message)
type toRawMessage|Email
? would that suffice for serializer to handle it properly?kor3k commentedon Jan 12, 2023
@fabpot please, could you explain why is it designed this way ( #33394 (comment) ) ? 🙏
as you are the author of these classes/logic.
understanding it will be a good start to wrap around this issue.
notably
RawMessage -> Message -> Email
RawMessage
seems to me that
RawMessage
is kinda substitute for an interface.Stop using JSON format for messenger as there is a bug in Symfony (see …
Stop using JSON format for messenger as there is a bug in Symfony (see …
macghriogair commentedon Oct 31, 2024
Any update on this one?
It seems kind of counter intuitive, having to configure an extra transport (which includes a separate failure transport, too) with native PHP Serializer, while all other transports are working with JSON.
On the other hand, when using
SendEmailMessage
, you are probably consuming the Mail with Symfony itself.Don't get me wrong, just wondering if this issue is a won't fix or needs support :)
Cafeine42 commentedon May 19, 2025
As rapid fix, I reused the Normalizer provided by @TheRatG (many thanks to them!) to work around this issue. I added a AutoconfigureTag to enable it faster. Tested on Sf 7.4.
What would be the best long-term solution here?
Should we consider revisiting the RawMessage class so it can be natively supported by the Symfony serializer? That could imply deprecating it in its current form and introducing a new class that would be fully supported wherever RawMessage is currently used.
Alternatively, could introducing a few interfaces help make things more flexible and extensible?
Or would it make more sense to simply include this Normalizer directly in the Mail component?
I'd love to hear your thoughts on the most sustainable path forward.