-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] HTML-Mail with TWIG Template and async transport #44439
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
IIUC, you put the entire email in the message envelope and you dispatch it? |
i am sorry but i dont know what you mean with
do i have a choice? I just |
IIUC :> If I Understand Correctly i do not know what mailer does from its side on async logic, i send async email like i've described to you :) |
I have the same problem on Symfony 4.* and 5.* $email = (new TemplatedEmail())
->from(new Address('[email protected]', 'Company'))
->to($user->getEmail())
->priority(TemplatedEmail::PRIORITY_HIGH)
->subject($translator->trans('Your password reset request'))
->htmlTemplate('reset_password/email.html.twig')
->context([
'resetToken' => $resetToken,
]);
$mailer->send($email); |
I've just run into this. I would have expected that when I do a Instead, the Mailer is serializing the |
@gubler Same issue here. I expected too that rendering is done before sending to the async transport.
|
Although my issue was not exactly the same, this issue helped me find out what the problem was. Some properties in the template were missing. It was caused by a custom __serialize() function in an object passed to the context. So to be safe, only use really simple DTOs in the context. I hope it can help someone. |
Calling the body renderer seems not be enough in all situations. When using custom Extending above work a round with some extra code to convert een templated email into a plain email seems to work.
|
The mailer renders the email in the async handler to get "better" headers (like a Date header that reflects when the email was sent). See #47075 for an easier way to render emails before sending them in 6.2 |
…(fabpot) This PR was merged into the 6.2 branch. Discussion ---------- [Mailer] Add more information about sending email async The example only works as of 6.2 thanks to symfony/symfony#47075 I've written this PR because we keep having issues like symfony/symfony#44439. So, documenting a bit more how it works internally might help people understand what to do. Commits ------- 4fbbc16 Add more information about sending email async
Symfony version(s) affected
5.*
Description
Trying to send a html mail with twig template (https://symfony.com/doc/current/mailer.html#html-content) with async transport (https://symfony.com/doc/current/mailer.html#sending-messages-async).
How to reproduce
The Problem occure in my case when putting an entity in the context of the mail object
In my case there are some ORM-Mapping (Many to...) to other Entities. Finally one of the mapped entities has an
Symfony\Component\HttpFoundation\File
in the property.Symfony\Component\Messenger\Transport\Serialization\PhpSerializer:encode()
useswhich will throw an exception, because
Symfony\Component\HttpFoundation\File
is not allowed to serialize (could also happen with other stuff).This Example is really just an example, but i actually will parse an entity to the twig template by
mail->context()
.This is not a szenario what will be often occure i think. But perhaps someone has an similar issue.
Possible Solution
Only use informations and object that you really need in the context (so an Entity is a bad idea)
Throw
context
out of theenvelop
object befor sending itThe text was updated successfully, but these errors were encountered: