Skip to content
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

Make Mandrill MessageId available to Laravel + sub accounts/headers bugfix #39

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

thybag
Copy link
Contributor

@thybag thybag commented Apr 3, 2023

Hi @luisdalmolin, hope this PR all looks okay. Please let me know if there is anything you would like tweaking.

Key changes involved

  1. Makes the Mandrill Message ID available to Laravel
  2. Adds some basic unit tests for new functionality
  3. Fixes a bug where headers were not being passed as part of the message payload.

Mandrill Message Id is now available via the event at

  • the sentMessage messageId property. e.g. $event->sent->getMessageId()
  • the X-Message-ID header $event->message->getHeaders()->get('X-Message-ID')

The X-Message-ID convention is taken from Laravel maintained mail drivers including the base SES driver.

The Unit tests work via injecting a mocked Guzzle instance into MailChimp. Tests then just double check the event gets back what it expects from the mandrill API and that all headers are submitted as expected.

While checking headers i also noticed these did not appear to be being correctly passed to the Mandrill API (most notably X-MC-Subaccount). I had to rework the logic a little to ensure these are set on the Message before the logic living in the abstract classes send method, as after this point the headers are updated on a copy of the data, not the actual data that will be sent via the API calls.

With luck this should resolve #30 and #31

This PR is just for visibility. Will PR upstream once complete.

Make the Mandrill message `id` accessible from the Laravel via the sent event. Message id is now available via
*  the `sentMessage` messageId property. `e.g. $event->sent->getMessageId()`
* the `X-Message-ID` header `$event->message->getHeaders()->get('X-Message-ID')`

The `X-Message-ID`  convention is taken from Laravel maintained mail drivers including the base SES driver.

Additionally fixes headers not being sent as part of the Mail payload, causing `X-MC-Subaccount` and similar headers not to work as expected. 

In theory this should resolve luisdalmolin#30 and luisdalmolin#31

Unit tests for the message _id retrieval and header submission have been added. This did require a minor change to the Transport in order to facilitate mocking of the underlying Guzzle instance.
@thybag thybag changed the title Make Mandrill MessageId available to Laravel + a sub accounts bugfix Make Mandrill MessageId available to Laravel + sub accounts/headers bugfix Apr 3, 2023
@luisdalmolin
Copy link
Owner

I'll tag this as a beta release for now, and once we get a few confirmations it's stable, I can tag a stable release.

@luisdalmolin luisdalmolin merged commit 8581525 into luisdalmolin:master Apr 6, 2023
@luisdalmolin
Copy link
Owner

Thank you!

@luisdalmolin
Copy link
Owner

@thybag
Copy link
Contributor Author

thybag commented Apr 25, 2023

Cheers. I hope its been working well for people so far.
I may do a follow up PR when i get a chance just to update the readme with how to get the mandrill message ID + if your interested a config for running tests via GH CI?

@luisdalmolin
Copy link
Owner

That would be awesome, actually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom headers not included in the message in Laravel 9
2 participants