feat: disable mailjet tracking on every mail
This commit is contained in:
1 parent
2ef831c5c4
commit
d760ed3cdf
6 files changed
+27
-29
No files matched your search
@@ -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)%'
|
||||
+1
-1
@@ -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.
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
+10
-10
@@ -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']) {
|
||||
// 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']);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user