feat: disable mailjet open and click tracking
This commit is contained in:
1 parent
77960fe81f
commit
980e378a7b
2 files changed
+45
No files matched your search
@@ -55,6 +55,14 @@ class Mailer
|
|||||||
->context($context)
|
->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) {
|
foreach ($config['attachments'] as $attachment) {
|
||||||
/* @var EmailAttachmentInterface $attachment */
|
/* @var EmailAttachmentInterface $attachment */
|
||||||
$attachment->attachTo($email);
|
$attachment->attachTo($email);
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Email;
|
||||||
|
|
||||||
|
use App\Email\Mailer;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
|
use Symfony\Component\Mime\BodyRendererInterface;
|
||||||
|
|
||||||
|
class MailerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Mailjet would otherwise track opens and rewrite links if the account is set to.
|
||||||
|
*/
|
||||||
|
public function testMailIsNotTracked(): void
|
||||||
|
{
|
||||||
|
$mailer = new Mailer(
|
||||||
|
$this->createStub(MailerInterface::class),
|
||||||
|
$this->createStub(BodyRendererInterface::class),
|
||||||
|
new NullLogger(),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
$headers = $mailer->create([], [
|
||||||
|
'from' => '[email protected]',
|
||||||
|
'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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user