diff --git a/config/packages/mailer.yaml b/config/packages/mailer.yaml index 434da98..8286bd2 100644 --- a/config/packages/mailer.yaml +++ b/config/packages/mailer.yaml @@ -3,7 +3,10 @@ framework: # "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 and the nightly cron reminders (App\Email\Mailer::MAILJET_TRANSPORT). - # Reordering this quietly moves the whole application to Mailjet. + # Reordering this quietly sends everything over MAILING_MAILER_DSN. + # + # Production points both DSNs at the same Mailjet account. The split keeps the volume + # mail on Mailjet should the low-volume mail ever move to another SMTP server. transports: main: '%env(MAILER_DSN)%' mailing: '%env(MAILING_MAILER_DSN)%' diff --git a/docs/operations.md b/docs/operations.md index aa0960a..c28526f 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -122,7 +122,7 @@ 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 - mailings and the nightly - cron reminders alike, which both go out over Mailjet. The quietest failure in the + cron reminders alike, which both go out over it. 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 0074711..c85c9dd 100644 --- a/src/Email/ApplicationFormSubmissionMailer.php +++ b/src/Email/ApplicationFormSubmissionMailer.php @@ -24,7 +24,8 @@ use Psr\Log\LoggerInterface; * confirmation would need machinery nothing else here has. * * 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). + * volume, the teamer mailing and the cron reminders (Mailer::MAILJET_TRANSPORT). Production + * points both at Mailjet. */ class ApplicationFormSubmissionMailer { diff --git a/src/Email/Mailer.php b/src/Email/Mailer.php index 69858c6..104e128 100644 --- a/src/Email/Mailer.php +++ b/src/Email/Mailer.php @@ -16,12 +16,12 @@ 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. + * reminders: Mailjet (MAILING_MAILER_DSN, mailer.yaml). Pass it as the 'transport' option; + * every other mail goes over MAILER_DSN. * - * Mail sent over it is never tracked, whatever the Mailjet account is set to: no open pixel, - * no links rewritten through Mailjet's redirect domain. Staff mail is not a campaign. + * Production points both DSNs at the same Mailjet account, so today the split changes + * nothing there. It keeps the volume mail on Mailjet should the low-volume mail ever move to + * another SMTP server. */ public const string MAILJET_TRANSPORT = 'mailing'; @@ -86,15 +86,15 @@ class Mailer $email->getHeaders()->addTextHeader('X-Transport', $config['transport']); } - // Mailjet tracks per its account settings unless a message says otherwise. These headers - // only work over SMTP (mailjet+smtp, the DSN we use) - the Send API refuses them - and - // Symfony's SMTP transport passes them through untouched. - if (self::MAILJET_TRANSPORT === $config['transport']) { - $email->getHeaders() - ->addTextHeader('X-Mailjet-TrackOpen', '0') - ->addTextHeader('X-Mailjet-TrackClick', '0') - ; - } + // No mail is tracked, whatever the Mailjet account is set to: no open pixel, no links + // rewritten through Mailjet's redirect domain - staff mail is not a campaign. On every mail, + // not just the volume transport, because production sends all of it over Mailjet; another + // SMTP server would merely pass the headers on. They only work over SMTP (mailjet+smtp, the + // DSN we use) - the Send API refuses them - and Symfony's SMTP transport leaves them alone. + $email->getHeaders() + ->addTextHeader('X-Mailjet-TrackOpen', '0') + ->addTextHeader('X-Mailjet-TrackClick', '0') + ; if (null !== $config['bus_transport']) { $email->getHeaders()->addTextHeader('X-Bus-Transport', $config['bus_transport']); diff --git a/src/Service/Teamer/TeamerMailingService.php b/src/Service/Teamer/TeamerMailingService.php index bbc63a5..d45cf24 100644 --- a/src/Service/Teamer/TeamerMailingService.php +++ b/src/Service/Teamer/TeamerMailingService.php @@ -29,8 +29,7 @@ class TeamerMailingService private const PREVIEW_SUBJECT_PREFIX = '[Vorschau] '; /** - * The mailer transport a mailing goes out over: Mailjet, rather than the webhoster's - * relay, see Mailer::MAILJET_TRANSPORT. + * The mailer transport for mail sent in volume, see Mailer::MAILJET_TRANSPORT. */ private const TRANSPORT = Mailer::MAILJET_TRANSPORT; diff --git a/tests/Email/MailerTest.php b/tests/Email/MailerTest.php index 0b0e427..96d5b35 100644 --- a/tests/Email/MailerTest.php +++ b/tests/Email/MailerTest.php @@ -14,28 +14,23 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; class MailerTest extends KernelTestCase { /** - * Mailjet would otherwise track opens and rewrite links if the account is set to, which staff - * mail - mailings and reminders alike - must not be. + * Mailjet would otherwise track opens and rewrite links if the account is set to. Production + * sends every mail over Mailjet, whichever transport it names, so none may be tracked. */ - public function testMailOverMailjetIsNotTracked(): void + #[\PHPUnit\Framework\Attributes\TestWith([Mailer::MAILJET_TRANSPORT])] + #[\PHPUnit\Framework\Attributes\TestWith([null])] + public function testNoMailIsTracked(?string $transport): void { - $headers = $this->create(Mailer::MAILJET_TRANSPORT)->getHeaders(); + $headers = $this->create($transport)->getHeaders(); - $this->assertSame(Mailer::MAILJET_TRANSPORT, $headers->get('X-Transport')?->getBodyAsString()); $this->assertSame('0', $headers->get('X-Mailjet-TrackOpen')?->getBodyAsString()); $this->assertSame('0', $headers->get('X-Mailjet-TrackClick')?->getBodyAsString()); } - /** - * The webhoster's relay would pass Mailjet headers on to the recipient as noise. - */ - public function testMailOverTheRelayCarriesNoMailjetHeaders(): void + public function testOnlyTheVolumeMailNamesItsTransport(): void { - $headers = $this->create(null)->getHeaders(); - - $this->assertFalse($headers->has('X-Transport')); - $this->assertFalse($headers->has('X-Mailjet-TrackOpen')); - $this->assertFalse($headers->has('X-Mailjet-TrackClick')); + $this->assertSame(Mailer::MAILJET_TRANSPORT, $this->create(Mailer::MAILJET_TRANSPORT)->getHeaders()->get('X-Transport')?->getBodyAsString()); + $this->assertFalse($this->create(null)->getHeaders()->has('X-Transport')); } /**