OpenBuildings / postmark

Postmark transport for Swift Mailer
https://github.com/OpenBuildings/postmark
BSD 3-Clause "New" or "Revised" License
16 stars 8 forks source link

Make the send method return the Postmark API response array. #21

Closed BradEstey closed 9 years ago

BradEstey commented 9 years ago

This will make $mailer->send($message); return the parsed array response from the Postmark API.

Alternatively, I guess a Swift_Events_ResponseEvent could be fired to via "responseReceived" with a string representation of the response or just the message ID. Then an instance of Swift_Events_ResponseListener can be registered and get that response. Seems like over-engineering a simple problem, but it would avoid changing the return 1 response from the send() method.

Possible use case: An email is sent and the message ID logged, then if Postmark reports a bounce, that log item can be retrieved and updated to reflect the bounced status.

hkdobrev commented 9 years ago

I'm concerned with backwards-compatibility. This is actually changing what would be returned. I agree what it returns at the moment - 0 or 1 is bad. But if someone checks the response like:

$ok = $mailer->send($message);

if ($ok) {
   // ...
}

we would break code in a bad way.

Do you think this would make more sense if it targets the master branch? I could add it to the 0.4.x milestone.

BradEstey commented 9 years ago

Here's the other option, which keeps the method returning 1, but now fires a response event that you can listen for containing the Message ID. The rest of the array response isn't really necessary, the Message ID is the big thing that you can then query against the API to get any additional info if needed.

hkdobrev commented 9 years ago

OK, I'll merge this in, try writing a test and will release a 0.1.x release with that. I'll open a new issue for returning the Postmark response in 0.4.

Cheers! :beers:

hkdobrev commented 9 years ago

@BradEstey I actually already released this under 0.1.7 with a test of my own. I was just about to close this as I prepared 0.2.x and 0.3.x releases.

BradEstey commented 9 years ago

Yay! Thanks. :+1:

hkdobrev commented 9 years ago

I will take your test as well, thanks!

hkdobrev commented 9 years ago

This landed in 0.1.7, 0.2.1 and 0.3.1.

I am looking forward to improve the event system in the transport. It is also currently lacking correct start/stop support.

I've opened #22 for the actual Postmark API response to be returned. Feel free to open a pull request for that against the master branch.

sprain commented 7 years ago

Sorry for popping in here, but I am kinda stuck: How do I listen to this responseReceived event in a Symfony app?

hkdobrev commented 6 years ago

How do I listen to this responseReceived event in a Symfony app?

You will need to access the Swift Mail event dispatcher somehow. I'm not familiar how to do that in Symfony, but you should be able to access it from the Swift Mailer instance in the DIC somehow.