Skip to content

[Mailer][Mailjet] MailjetApiTransport SentMessage MessageId is Request ID #48550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mdawart opened this issue Dec 8, 2022 · 3 comments
Closed

Comments

@mdawart
Copy link
Contributor

mdawart commented Dec 8, 2022

Symfony version(s) affected

5.4

Description

The ID assigned using $sentMessage->setMessageId is an ID generated by MailjetAPI for the request but not for the message. If you want to identify messages on webhooks (e.g. bounce or block see https://dev.mailjet.com/email/guides/webhooks/ ) it would not work, you need the MessageUUID

I got this feedback from their support:

Yes, correct, these values are of the same format, but are assigned to different things.
The MessageUUID is the ID of the message.
The x-mj-request-guid is the ID of the API request. This is solely saved for us, for logging purposes.

Problem is in case there is more than one Recipient more than one MessageUUID is generated and SentMessage can only store a single Id for a message.

https://dev.mailjet.com/email/guides/send-api-v31/#send-a-basic-email

How to reproduce

Send a message using the MailjetApiTransport

Possible Solution

If you need to identify email messages send them as custom headers
$email->getHeaders()->addHeader('MessageID', $this->messageId);
and rely on the value coming back on webhook calls

Additional Context

I am not sure if bug is the right label for this, maybe this is just something to add to the documentation.

@OskarStark
Copy link
Contributor

We could implode all messageUUIDs as one string an store this as the messageID

WDYT @fabpot ?

@fabpot
Copy link
Member

fabpot commented Dec 9, 2022

That's an interesting behavior.
I think we need first to investigate if more than just Mailjet has this same behavior. And then see how we can make it natively supported. I would not store all of them as one, except if Mailjet is unique in its behavior.

@mdawart
Copy link
Contributor Author

mdawart commented Dec 14, 2022

I checked this for MessageBird Notifier. MessageBirds API provides only a single id even if there is more than one recipient. And as far as I understand SmsMessage implements MessageInterface can only have one recipient anyway.

So this should be the same for EmailMessage implements MessageInterface but when using the Mailjet Bridge with Mailer I assume it is possible to add more than one Recipient and in this case Mailjet API would generate a MessageUUID for each of them.

nicolas-grekas added a commit that referenced this issue Apr 18, 2023
…est-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants