From 8898320e210295fca360970954206349e83d734a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 10 Nov 2026 17:13:05 +0100 Subject: [PATCH] feat: send all cron reminders over mailjet --- config/packages/mailer.yaml | 3 ++- docs/operations.md | 3 ++- src/Email/ApplicationFormSubmissionMailer.php | 4 ++-- src/Email/Mailer.php | 8 ++++++++ src/Service/Cron/DispositionReminderService.php | 2 +- src/Service/Cron/FeedbackReminderService.php | 1 + src/Service/Cron/QuestionnaireReminderService.php | 1 + src/Service/Cron/SeasonTaskReminderService.php | 2 ++ src/Service/Cron/UploadReminderService.php | 1 + src/Service/Cron/WorkMonthReminderService.php | 1 + src/Service/Teamer/TeamerMailingService.php | 5 ++--- tests/Service/Cron/QuestionnaireReminderServiceTest.php | 2 ++ tests/Service/Cron/UploadReminderServiceTest.php | 3 ++- 13 files changed, 27 insertions(+), 9 deletions(-) diff --git a/config/packages/mailer.yaml b/config/packages/mailer.yaml index 6473358..434da98 100644 --- a/config/packages/mailer.yaml +++ b/config/packages/mailer.yaml @@ -2,7 +2,8 @@ framework: mailer: # "main" has to stay first: it is the transport every mail without an explicit # X-Transport header goes out over, which is all of them apart from the teamer - # mailing. Reordering this quietly moves the whole application to Mailjet. + # mailing and the nightly cron reminders (App\Email\Mailer::MAILJET_TRANSPORT). + # Reordering this quietly moves the whole application to Mailjet. transports: main: '%env(MAILER_DSN)%' mailing: '%env(MAILING_MAILER_DSN)%' diff --git a/docs/operations.md b/docs/operations.md index f355311..aa0960a 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -121,7 +121,8 @@ Three failure modes worth knowing because they are quiet rather than loud: - **`.env.local` missing from the deploy path.** `APP_ENV` falls back to `dev` and `MAILING_MAILER_DSN` to `null://null`. The worker then consumes every message and - delivers nothing, reporting success and recording no failure. The quietest failure in the + delivers nothing, reporting success and recording no failure - mailings and the nightly + cron reminders alike, which both go out over Mailjet. The quietest failure in the whole system. - **No worker consuming `mailing`.** Mailings queue up indefinitely while the admin is told they are on their way. `messenger:stats` shows it immediately. diff --git a/src/Email/ApplicationFormSubmissionMailer.php b/src/Email/ApplicationFormSubmissionMailer.php index b33b908..0074711 100644 --- a/src/Email/ApplicationFormSubmissionMailer.php +++ b/src/Email/ApplicationFormSubmissionMailer.php @@ -23,8 +23,8 @@ use Psr\Log\LoggerInterface; * is called inside the visitor's own form submission on another website. A delivery * confirmation would need machinery nothing else here has. * - * Goes over MAILER_DSN like every transactional mail; MAILING_MAILER_DSN is for the bulk teamer - * mailing only. + * Goes over MAILER_DSN like every transactional mail; MAILING_MAILER_DSN is for mail sent in + * volume, the teamer mailing and the cron reminders (Mailer::MAILJET_TRANSPORT). */ class ApplicationFormSubmissionMailer { diff --git a/src/Email/Mailer.php b/src/Email/Mailer.php index 1cacf9d..2c96d7a 100644 --- a/src/Email/Mailer.php +++ b/src/Email/Mailer.php @@ -14,6 +14,14 @@ use Symfony\Contracts\Translation\TranslatorInterface; class Mailer { + /** + * The mailer transport for mail sent in volume - the teamer mailing and the nightly cron + * reminders: Mailjet (MAILING_MAILER_DSN, mailer.yaml), rather than the webhoster's relay that + * carries every other mail, which would risk the hosting account at a few hundred mails. Pass + * it as the 'transport' option. + */ + public const string MAILJET_TRANSPORT = 'mailing'; + public function __construct( private readonly MailerInterface $mailer, private readonly BodyRendererInterface $bodyRenderer, diff --git a/src/Service/Cron/DispositionReminderService.php b/src/Service/Cron/DispositionReminderService.php index 9d0159e..ad35576 100644 --- a/src/Service/Cron/DispositionReminderService.php +++ b/src/Service/Cron/DispositionReminderService.php @@ -75,7 +75,7 @@ class DispositionReminderService $this->mailer->createAndSendText( EmailTextKey::REMINDER_DISPOSITION, $this->placeholderFactory->forDispositionReminder($disposition, self::REMINDER_LEAD_DAYS), - ['to' => $teamer->getCommunication()->getEmail()], + ['to' => $teamer->getCommunication()->getEmail(), 'transport' => Mailer::MAILJET_TRANSPORT], ); } diff --git a/src/Service/Cron/FeedbackReminderService.php b/src/Service/Cron/FeedbackReminderService.php index f35ddc9..b476518 100644 --- a/src/Service/Cron/FeedbackReminderService.php +++ b/src/Service/Cron/FeedbackReminderService.php @@ -81,6 +81,7 @@ class FeedbackReminderService 'to' => $manager->getEmail(), 'subject' => 'Reminder: Offene Feedbacks', 'template' => 'email/reminder_pending_feedback.html.twig', + 'transport' => Mailer::MAILJET_TRANSPORT, ]); } diff --git a/src/Service/Cron/QuestionnaireReminderService.php b/src/Service/Cron/QuestionnaireReminderService.php index 8f928ea..a881333 100644 --- a/src/Service/Cron/QuestionnaireReminderService.php +++ b/src/Service/Cron/QuestionnaireReminderService.php @@ -65,6 +65,7 @@ class QuestionnaireReminderService )), ], [ 'to' => $email, + 'transport' => Mailer::MAILJET_TRANSPORT, ]); ++$count; diff --git a/src/Service/Cron/SeasonTaskReminderService.php b/src/Service/Cron/SeasonTaskReminderService.php index 2c55b1e..ae847cc 100644 --- a/src/Service/Cron/SeasonTaskReminderService.php +++ b/src/Service/Cron/SeasonTaskReminderService.php @@ -77,6 +77,7 @@ class SeasonTaskReminderService ], [ 'subject' => 'Fristen für Saisonunterlagen erreicht', 'template' => 'email/season_deadlines.html.twig', + 'transport' => Mailer::MAILJET_TRANSPORT, ]); $message = 'Sent the season task deadline summary for '.$count.' teamers'; @@ -146,6 +147,7 @@ class SeasonTaskReminderService 'tasks' => implode(', ', $entry['labels']), ], [ 'to' => $email, + 'transport' => Mailer::MAILJET_TRANSPORT, ]); ++$count; diff --git a/src/Service/Cron/UploadReminderService.php b/src/Service/Cron/UploadReminderService.php index db91dc3..4783f1d 100644 --- a/src/Service/Cron/UploadReminderService.php +++ b/src/Service/Cron/UploadReminderService.php @@ -107,6 +107,7 @@ class UploadReminderService { $this->mailer->createAndSendText($key, $placeholders, [ 'to' => $disposition->getTeamer()->getCommunication()->getEmail(), + 'transport' => Mailer::MAILJET_TRANSPORT, ]); } } diff --git a/src/Service/Cron/WorkMonthReminderService.php b/src/Service/Cron/WorkMonthReminderService.php index 7a10a42..2ced9b6 100644 --- a/src/Service/Cron/WorkMonthReminderService.php +++ b/src/Service/Cron/WorkMonthReminderService.php @@ -62,6 +62,7 @@ class WorkMonthReminderService 'workMonth' => $workMonth->getPeriodLabel(), ], [ 'to' => $email, + 'transport' => Mailer::MAILJET_TRANSPORT, ]); ++$count; diff --git a/src/Service/Teamer/TeamerMailingService.php b/src/Service/Teamer/TeamerMailingService.php index 917a95f..bbc63a5 100644 --- a/src/Service/Teamer/TeamerMailingService.php +++ b/src/Service/Teamer/TeamerMailingService.php @@ -30,10 +30,9 @@ class TeamerMailingService /** * The mailer transport a mailing goes out over: Mailjet, rather than the webhoster's - * relay that carries every other mail, which would risk the hosting account over a few - * hundred recipients. Configured in mailer.yaml. + * relay, see Mailer::MAILJET_TRANSPORT. */ - private const TRANSPORT = 'mailing'; + private const TRANSPORT = Mailer::MAILJET_TRANSPORT; public function __construct( private readonly TeamerRepository $teamerRepository, diff --git a/tests/Service/Cron/QuestionnaireReminderServiceTest.php b/tests/Service/Cron/QuestionnaireReminderServiceTest.php index 72a4653..d2ae3a2 100644 --- a/tests/Service/Cron/QuestionnaireReminderServiceTest.php +++ b/tests/Service/Cron/QuestionnaireReminderServiceTest.php @@ -67,6 +67,8 @@ class QuestionnaireReminderServiceTest extends TestCase ->method('createAndSendText') ->willReturnCallback(function (EmailTextKey $key, array $placeholders, array $options) use (&$sent): void { $this->assertSame(EmailTextKey::REMINDER_QUESTIONNAIRE, $key); + // over Mailjet, like every cron reminder + $this->assertSame(Mailer::MAILJET_TRANSPORT, $options['transport']); $sent[$options['to']] = $placeholders['destinations']; }) ; diff --git a/tests/Service/Cron/UploadReminderServiceTest.php b/tests/Service/Cron/UploadReminderServiceTest.php index 17e5d60..739fb94 100644 --- a/tests/Service/Cron/UploadReminderServiceTest.php +++ b/tests/Service/Cron/UploadReminderServiceTest.php @@ -153,7 +153,8 @@ class UploadReminderServiceTest extends TestCase EmailTextKey::REMINDER_INVOICE_UPLOAD, $this->callback(fn (array $placeholders): bool => self::INVOICE_DEADLINE_DAYS === $placeholders['invoiceUploadDeadlineDays'] && 'Skireise' === substr((string) $placeholders['destination'], -8)), - ['to' => 'teamer@example.com'], + // over Mailjet, like every cron reminder (Mailer::MAILJET_TRANSPORT) + ['to' => 'teamer@example.com', 'transport' => Mailer::MAILJET_TRANSPORT], ) ;