diff --git a/src/Email/Mailer.php b/src/Email/Mailer.php index c4eb3348..853075ec 100644 --- a/src/Email/Mailer.php +++ b/src/Email/Mailer.php @@ -55,6 +55,14 @@ class Mailer ->context($context) ; + // Mailjet tracks per its account settings unless a message says otherwise: an open pixel + // and links rewritten through its redirect domain. These headers only work over SMTP - the + // Send API refuses them - and Symfony's SMTP transport passes them through untouched. + $email->getHeaders() + ->addTextHeader('X-Mailjet-TrackOpen', '0') + ->addTextHeader('X-Mailjet-TrackClick', '0') + ; + foreach ($config['attachments'] as $attachment) { /* @var EmailAttachmentInterface $attachment */ $attachment->attachTo($email); diff --git a/tests/Email/MailerTest.php b/tests/Email/MailerTest.php new file mode 100644 index 00000000..706c5892 --- /dev/null +++ b/tests/Email/MailerTest.php @@ -0,0 +1,37 @@ +createStub(MailerInterface::class), + $this->createStub(BodyRendererInterface::class), + new NullLogger(), + [], + ); + + $headers = $mailer->create([], [ + 'from' => 'test@example.com', + 'subject' => 'Betreff', + 'template' => 'email/test.html.twig', + 'attachments' => [], + ])->getHeaders(); + + self::assertSame('0', $headers->get('X-Mailjet-TrackOpen')?->getBodyAsString()); + self::assertSame('0', $headers->get('X-Mailjet-TrackClick')?->getBodyAsString()); + } +}