Skip to content

Commit 8b65de5

Browse files
bug #49992 [Mailer] [Mailjet] Use body MessageID instead of X-MJ-Request-GUID (Starfox64)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Mailer] [Mailjet] Use body MessageID instead of X-MJ-Request-GUID | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48550 | License | MIT | Doc PR | N/A As per #48550, the message ID of the `SentMessage` returned by the `MailjetApiTransport` is the `X-MJ-Request-GUID`. The issue is that this ID is only there for debug purposes by the MailJet engineers and cannot be consumed by the MailJet API to query the message metadata. This change instead uses the `MessageID` attribute returned in the JSON body of the response which can be used in further API requests. As the existing message ID was not usable for anything besides opening support tickets (which the new ID can still be used for), I've decided to submit this PR as a bug fix. A slight limitation however is that MailJet will return multiple messages when sending to multiple recipients, each having their own `MessageID`. This implementation therefore only returns the first `MessageID`, there is an ongoing discussion on #48550 about that behavior but I am submitting this PR as is since it's still a net improvement over the previous ID. Commits ------- 8b92751 [Mailer] [Mailjet] Use body MessageID instead of X-MJ-Request-GUID
2 parents 8198830 + 8b92751 commit 8b65de5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Symfony/Component/Mailer/Bridge/Mailjet/Tests/Transport/MailjetApiTransportTest.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,21 @@ public function testSendSuccess()
102102
{
103103
$json = json_encode([
104104
'Messages' => [
105-
'foo' => 'bar',
105+
[
106+
'Status' => 'success',
107+
'To' => [
108+
[
109+
'Email' => 'passenger1@mailjet.com',
110+
'MessageUUID' => '7c5f9f29-42ba-4959-b19c-dcd8b2f327ca',
111+
'MessageID' => '576460756513665525',
112+
'MessageHref' => 'https://api.mailjet.com/v3/message/576460756513665525',
113+
],
114+
],
115+
],
106116
],
107117
]);
108118

109-
$responseHeaders = [
110-
'x-mj-request-guid' => ['baz'],
111-
];
112-
113-
$response = new MockResponse($json, ['response_headers' => $responseHeaders]);
119+
$response = new MockResponse($json);
114120

115121
$client = new MockHttpClient($response);
116122

@@ -124,7 +130,7 @@ public function testSendSuccess()
124130

125131
$sentMessage = $transport->send($email);
126132
$this->assertInstanceOf(SentMessage::class, $sentMessage);
127-
$this->assertSame('baz', $sentMessage->getMessageId());
133+
$this->assertSame('576460756513665525', $sentMessage->getMessageId());
128134
}
129135

130136
public function testSendWithDecodingException()

src/Symfony/Component/Mailer/Bridge/Mailjet/Transport/MailjetApiTransport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
8585
throw new HttpTransportException(sprintf('Unable to send an email: "%s" malformed api response.', $response->getContent(false)), $response);
8686
}
8787

88-
$sentMessage->setMessageId($response->getHeaders(false)['x-mj-request-guid'][0]);
88+
$sentMessage->setMessageId($result['Messages'][0]['To'][0]['MessageID'] ?? '');
8989

9090
return $response;
9191
}

0 commit comments

Comments
 (0)