feat: markdown in email body for mailing and transactional
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Service\Teamer;
|
||||
|
||||
use App\Email\MailBodyRenderer;
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\User;
|
||||
use App\Message\SendTeamerMailing;
|
||||
@@ -37,6 +38,7 @@ class TeamerMailingService
|
||||
public function __construct(
|
||||
private readonly TeamerRepository $teamerRepository,
|
||||
private readonly Mailer $mailer,
|
||||
private readonly MailBodyRenderer $mailBodyRenderer,
|
||||
private readonly LoggerInterface $logger,
|
||||
// messenger transport, "mailing" in production and "sync" in dev and test,
|
||||
// see the parameter of the same name in services.yaml
|
||||
@@ -98,7 +100,7 @@ class TeamerMailingService
|
||||
$this->sendTo(
|
||||
$recipient['email'],
|
||||
$this->render($mailing->getSubject(), $values),
|
||||
$this->render($mailing->getMessage(), $values),
|
||||
$this->mailBodyRenderer->render($mailing->getMessage(), $values),
|
||||
self::TRANSPORT,
|
||||
$this->mailingBusTransport
|
||||
);
|
||||
@@ -121,7 +123,7 @@ class TeamerMailingService
|
||||
$this->sendTo(
|
||||
$admin->getUserIdentifier(),
|
||||
self::PREVIEW_SUBJECT_PREFIX.$this->render($mailingDto->getSubject(), $values),
|
||||
$this->render($mailingDto->getMessage(), $values)
|
||||
$this->mailBodyRenderer->render($mailingDto->getMessage(), $values)
|
||||
);
|
||||
|
||||
$this->logger->info('Send teamer mailing preview', [
|
||||
@@ -131,8 +133,10 @@ class TeamerMailingService
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the known placeholders. Anything that merely looks like a placeholder is
|
||||
* left alone - a typo should not silently blank out part of the mail.
|
||||
* Replace the known placeholders in a subject line. Anything that merely looks like a
|
||||
* placeholder is left alone - a typo should not silently blank out part of the mail.
|
||||
* The message body does not come through here: it is Markdown, and
|
||||
* App\Email\MailBodyRenderer has to escape the values before it puts them in.
|
||||
*/
|
||||
public function render(?string $text, array $values): string
|
||||
{
|
||||
@@ -195,12 +199,14 @@ class TeamerMailingService
|
||||
private function sendTo(
|
||||
string $email,
|
||||
string $subject,
|
||||
string $message,
|
||||
string $bodyHtml,
|
||||
?string $transport = null,
|
||||
?string $busTransport = null,
|
||||
): void {
|
||||
// $bodyHtml is already rendered and escaped mail HTML, see MailBodyRenderer -
|
||||
// email/teamer_mailing.html.twig prints it with |raw.
|
||||
$this->mailer->createAndSendEmail([
|
||||
'message' => $message,
|
||||
'bodyHtml' => $bodyHtml,
|
||||
], [
|
||||
'to' => $email,
|
||||
'subject' => $subject,
|
||||
|
||||
Reference in New Issue
Block a user