-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
6.2
Description
After updating to 6.2 I got this message:
Handling "Symfony\Component\Mailer\Messenger\SendEmailMessage" failed: You must configure a "Symfony\Component\Mime\BodyRendererInterface" when a "Symfony\Bridge\Twig\Mime\NotificationEmail" instance has a text or HTML template set. (500 Internal Server Error)
But when I try:
$this->bodyRenderer->render($message);
I get the error:
TypeError: Symfony\Bridge\Twig\Mime\BodyRenderer::render(): Argument #1 ($message) must be of type Symfony\Component\Mime\Message, Symfony\Component\Notifier\Message\EmailMessage given
How to reproduce
NewNotificationByEmail.php
...
class NewNotificationByEmail implements NewNotificationInterface
{
...
public function __invoke(array $pdfsName, int $entityId, string $entityToken, string $clientEmail, string $template)
{
...
try {
$clientNotification = new ClientNewNotificationByEmail($entityToken, $attachments, $template);
$this->notifier->send($clientNotification, new Recipient($clientEmail));
} catch (Exception $e) {
$this->logger->critical('Failed to notify client', ['error'=>$e->getMessage(), 'code'=>$e->getCode(), 'file'=>$e->getFile(), 'line'=>$e->getLine(), 'id'=>$entityId]);
throw $e;
}
}
}
ClientNewNotificationByEmail.php
...
class ClientNewNotificationByEmail extends Notification implements EmailNotificationInterface {
...
public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
{
$message = EmailMessage::fromNotification($this, $recipient, $transport);
$message->getMessage()
->htmlTemplate($this->template)
->context(['entityToken' => $this->entityToken, 'footer_text'=>null])
->importance('')
;
foreach ($this->attachments as $att) {
$message->getMessage()->attachFromPath($att['path'], $att['name'], 'application/pdf');
}
return $message;
}
}
Possible Solution
No response
Additional Context
No response
indapublic