mailer = $mailer; $this->logger = $logger; $this->translator = $translator; } public function postPersistComment(NotificationComment $comment, LifecycleEventArgs $eventArgs): void { foreach ( array_merge( $comment->getNotification()->getAddressees()->toArray(), [$comment->getNotification()->getSender()] ) as $dest ) { if (null === $dest->getEmail() || $comment->getCreatedBy() !== $dest) { continue; } $email = new TemplatedEmail(); $email ->to($dest->getEmail()) ->subject('Re: ' . $comment->getNotification()->getTitle()) ->textTemplate('@ChillMain/Notification/email_notification_comment_persist.fr.md.twig') ->context([ 'comment' => $comment, 'dest' => $dest, ]); try { $this->mailer->send($email); } catch (TransportExceptionInterface $e) { $this->logger->warning('[NotificationMailer] could not send an email notification about comment', [ 'to' => $dest->getEmail(), 'error_message' => $e->getMessage(), 'error_trace' => $e->getTraceAsString(), ]); } } } /** * Send a email after a notification is persisted. */ public function postPersistNotification(Notification $notification, LifecycleEventArgs $eventArgs): void { foreach ($notification->getAddressees() as $addressee) { if (null === $addressee->getEmail()) { continue; } $email = new Email(); $email ->subject($notification->getTitle()); if ($notification->isSystem()) { $email ->text($notification->getMessage()); } else { $email = new TemplatedEmail(); $email ->textTemplate('@ChillMain/Notification/email_non_system_notification_content.fr.md.twig') ->context([ 'notification' => $notification, 'dest' => $addressee, ]); } $email->to($addressee->getEmail()); try { $this->mailer->send($email); } catch (TransportExceptionInterface $e) { $this->logger->warning('[NotificationMailer] could not send an email notification', [ 'to' => $addressee->getEmail(), 'error_message' => $e->getMessage(), 'error_trace' => $e->getTraceAsString(), ]); } } } }