Skip to content

Commit 91f8966

Browse files
committed
feature symfony#61775 [Mailer][Mandrill] Add subaccount to the payload (andrehoong-pixieset)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [Mailer][Mandrill] Add `subaccount` to the payload | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | N/A | License | MIT <!-- 🛠️ Replace this text with a concise explanation of your change: - Adds support for MailChimp / Mandrill's subaccount feature - https://mailchimp.com/developer/transactional/docs/subaccounts/ - When emails are sent through the API, there is an option to set the subaccount parameter under [message][subaccount]. The current MandrillApiTransport class does not support this. - If emails are sent through SMTP the subaccount can be specified by setting the `X-MC-Subaccount` header - Proposal: If the X-MC-Subaccount header is present the MandrillApiTransport should set the [message][subaccount] field in the JSON it sends to the API Contributor guidelines: - ✅ Add tests and ensure they pass - 🐞 Bug fixes must target the **lowest maintained** branch where they apply https://symfony.com/releases#maintained-symfony-branches - ✨ New features and deprecations must target the **feature** branch and must add an entry to the changelog file of the patched component: https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - 🔒 Do not break backward compatibility: https://symfony.com/bc --> Commits ------- f5b2050 [Mailer][Mandrill] Add `subaccount` to the payload
2 parents b97c70e + f5b2050 commit 91f8966

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/Symfony/Component/Mailer/Bridge/Mailchimp/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add support for specifying a subaccount using the `X-MC-Subaccount` header
8+
49
7.2
510
---
611

src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillApiTransportTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ public function testCustomHeader()
6666
$this->assertEquals('bar', $payload['message']['headers']['foo']);
6767
}
6868

69+
public function testSubaccountHeaderIsAddedToPayload()
70+
{
71+
$email = new Email();
72+
$email->getHeaders()->addTextHeader('X-MC-Subaccount', 'foo-bar');
73+
$envelope = new Envelope(new Address('[email protected]'), [new Address('[email protected]')]);
74+
75+
$transport = new MandrillApiTransport('ACCESS_KEY');
76+
$method = new \ReflectionMethod(MandrillApiTransport::class, 'getPayload');
77+
$payload = $method->invoke($transport, $email, $envelope);
78+
79+
$this->assertArrayHasKey('subaccount', $payload['message']);
80+
$this->assertEquals('foo-bar', $payload['message']['subaccount']);
81+
$this->assertArrayNotHasKey('headers', $payload['message']);
82+
}
83+
6984
public function testSend()
7085
{
7186
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ private function getPayload(Email $email, Envelope $envelope): array
9393
],
9494
];
9595

96+
if ($email->getHeaders()->get('X-MC-Subaccount')) {
97+
$payload['message']['subaccount'] = $email->getHeaders()->get('X-MC-Subaccount')->getBodyAsString();
98+
}
99+
96100
if ('' !== $envelope->getSender()->getName()) {
97101
$payload['message']['from_name'] = $envelope->getSender()->getName();
98102
}
@@ -118,7 +122,7 @@ private function getPayload(Email $email, Envelope $envelope): array
118122
}
119123

120124
foreach ($email->getHeaders()->all() as $name => $header) {
121-
if (\in_array($name, ['from', 'to', 'cc', 'bcc', 'subject', 'content-type'], true)) {
125+
if (\in_array($name, ['from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'x-mc-subaccount'], true)) {
122126
continue;
123127
}
124128

0 commit comments

Comments
 (0)