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
|
# "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
|
# 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).
|
# 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:
|
transports:
|
||||||
main: '%env(MAILER_DSN)%'
|
main: '%env(MAILER_DSN)%'
|
||||||
mailing: '%env(MAILING_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
|
- **`.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
|
`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
|
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.
|
whole system.
|
||||||
- **No worker consuming `mailing`.** Mailings queue up indefinitely while the admin is told
|
- **No worker consuming `mailing`.** Mailings queue up indefinitely while the admin is told
|
||||||
they are on their way. `messenger:stats` shows it immediately.
|
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.
|
* confirmation would need machinery nothing else here has.
|
||||||
*
|
*
|
||||||
* Goes over MAILER_DSN like every transactional mail; MAILING_MAILER_DSN is for mail sent in
|
* 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
|
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
|
* 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
|
* reminders: Mailjet (MAILING_MAILER_DSN, mailer.yaml). Pass it as the 'transport' option;
|
||||||
* carries every other mail, which would risk the hosting account at a few hundred mails. Pass
|
* every other mail goes over MAILER_DSN.
|
||||||
* it as the 'transport' option.
|
|
||||||
*
|
*
|
||||||
* Mail sent over it is never tracked, whatever the Mailjet account is set to: no open pixel,
|
* Production points both DSNs at the same Mailjet account, so today the split changes
|
||||||
* no links rewritten through Mailjet's redirect domain. Staff mail is not a campaign.
|
* 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';
|
public const string MAILJET_TRANSPORT = 'mailing';
|
||||||
|
|
||||||
@@ -86,15 +86,15 @@ class Mailer
|
|||||||
$email->getHeaders()->addTextHeader('X-Transport', $config['transport']);
|
$email->getHeaders()->addTextHeader('X-Transport', $config['transport']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mailjet tracks per its account settings unless a message says otherwise. These headers
|
// No mail is tracked, whatever the Mailjet account is set to: no open pixel, no links
|
||||||
// only work over SMTP (mailjet+smtp, the DSN we use) - the Send API refuses them - and
|
// rewritten through Mailjet's redirect domain - staff mail is not a campaign. On every mail,
|
||||||
// Symfony's SMTP transport passes them through untouched.
|
// not just the volume transport, because production sends all of it over Mailjet; another
|
||||||
if (self::MAILJET_TRANSPORT === $config['transport']) {
|
// 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()
|
$email->getHeaders()
|
||||||
->addTextHeader('X-Mailjet-TrackOpen', '0')
|
->addTextHeader('X-Mailjet-TrackOpen', '0')
|
||||||
->addTextHeader('X-Mailjet-TrackClick', '0')
|
->addTextHeader('X-Mailjet-TrackClick', '0')
|
||||||
;
|
;
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $config['bus_transport']) {
|
if (null !== $config['bus_transport']) {
|
||||||
$email->getHeaders()->addTextHeader('X-Bus-Transport', $config['bus_transport']);
|
$email->getHeaders()->addTextHeader('X-Bus-Transport', $config['bus_transport']);
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ class TeamerMailingService
|
|||||||
private const PREVIEW_SUBJECT_PREFIX = '[Vorschau] ';
|
private const PREVIEW_SUBJECT_PREFIX = '[Vorschau] ';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mailer transport a mailing goes out over: Mailjet, rather than the webhoster's
|
* The mailer transport for mail sent in volume, see Mailer::MAILJET_TRANSPORT.
|
||||||
* relay, see Mailer::MAILJET_TRANSPORT.
|
|
||||||
*/
|
*/
|
||||||
private const TRANSPORT = Mailer::MAILJET_TRANSPORT;
|
private const TRANSPORT = Mailer::MAILJET_TRANSPORT;
|
||||||
|
|
||||||
|
|||||||
@@ -14,28 +14,23 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|||||||
class MailerTest extends KernelTestCase
|
class MailerTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Mailjet would otherwise track opens and rewrite links if the account is set to, which staff
|
* Mailjet would otherwise track opens and rewrite links if the account is set to. Production
|
||||||
* mail - mailings and reminders alike - must not be.
|
* 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-TrackOpen')?->getBodyAsString());
|
||||||
$this->assertSame('0', $headers->get('X-Mailjet-TrackClick')?->getBodyAsString());
|
$this->assertSame('0', $headers->get('X-Mailjet-TrackClick')?->getBodyAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testOnlyTheVolumeMailNamesItsTransport(): void
|
||||||
* The webhoster's relay would pass Mailjet headers on to the recipient as noise.
|
|
||||||
*/
|
|
||||||
public function testMailOverTheRelayCarriesNoMailjetHeaders(): void
|
|
||||||
{
|
{
|
||||||
$headers = $this->create(null)->getHeaders();
|
$this->assertSame(Mailer::MAILJET_TRANSPORT, $this->create(Mailer::MAILJET_TRANSPORT)->getHeaders()->get('X-Transport')?->getBodyAsString());
|
||||||
|
$this->assertFalse($this->create(null)->getHeaders()->has('X-Transport'));
|
||||||
$this->assertFalse($headers->has('X-Transport'));
|
|
||||||
$this->assertFalse($headers->has('X-Mailjet-TrackOpen'));
|
|
||||||
$this->assertFalse($headers->has('X-Mailjet-TrackClick'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user