Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Mailer] Add more information about sending email async#17065
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1204,9 +1204,38 @@ you have a transport called ``async``, you can route the message there: | ||
| ->senders(['async']); | ||
| }; | ||
| Thanks to this, instead of being delivered immediately, messages will be sent | ||
| to the transport to be handled later (see :ref:`messenger-worker`). Note that | ||
| the "rendering" of the email (computed headers, body rendering, ...) is also | ||
| deferred and will only happen just before the email is sent by the Messenger | ||
| handler. | ||
| .. versionadded:: 6.2 | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Imho this should be a warning, otherwise it gets removed in Symfony 7 docs MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Having this removed in 7.0 is a good thing. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Done then | ||
| The following example about rendering the email before calling | ||
| ``$mailer->send($email)`` works as of Symfony 6.2. | ||
| When sending an email asynchronously, its instance must be serializable. | ||
| This is always the case for :class:`Symfony\\Bridge\\Twig\\Mime\\Email` | ||
| instances, but when sending a | ||
| :class:`Symfony\\Bridge\\Twig\\Mime\\TemplatedEmail`, you must ensure that | ||
| the ``context`` is serializable. If you have non-serializable variables, | ||
| like Doctrine entities, either replace them with more specific variables or | ||
| render the email before calling ``$mailer->send($email)``:: | ||
| use Symfony\Component\Mailer\MailerInterface; | ||
| use Symfony\Component\Mime\BodyRendererInterface; | ||
| public function action(MailerInterface $mailer, BodyRendererInterface $bodyRenderer) | ||
| { | ||
| $email = (new TemplatedEmail()) | ||
| ->htmlTemplate($template) | ||
| ->context($context) | ||
| ; | ||
| $bodyRenderer->render($email); | ||
| $mailer->send($email); | ||
| } | ||
| You can configure which bus is used to dispatch the message using the ``message_bus`` option. | ||
| You can also set this to ``false`` to call the Mailer transport directly and | ||