Skip to content

Conversation

@mymah01
Copy link

@mymah01 mymah01 commented Sep 18, 2025

Summary

This PR updates PMMail.send() and PMBatchMail.send() to return the parsed JSON response from the Postmark API instead of only True/False.

This makes it possible for client code to access useful details such as MessageID, ErrorCode, and Message without re-calling the API.

Changes

Updated PMMail.send() to return the JSON object from Postmark.
Updated PMBatchMail.send() to return a list of JSON objects (one per message).
Updated unit tests to cover both single and batch send scenarios, mocking urlopen to simulate Postmark responses.

Motivation

The previous implementation returned only a boolean, which limited insight into failures or response metadata. Returning the full response allows better error handling and logging.

Example
mail = PMMail(
    api_key="test-api-key",
    sender="sender@example.com",
    to="receiver@example.com",
    subject="Hello",
    text_body="Testing single mail return",
)
result = mail.send()
print(result["MessageID"])  # now accessible
Tests

✅ test_mail_returns_result added for PMMail
✅ test_batch_mail_returns_results added for PMBatchMail

@nicholasserra
Copy link
Collaborator

Thanks! I like it. We'll probably just need to bump the major version on this package, as there's likely people checking that boolean response on send. Will think on it a bit.

@mymah01
Copy link
Author

mymah01 commented Sep 23, 2025

Awesome, another option would be to add a check, or allow for an opt-in, i.e.:

return_json = False
return parsed if return_json else True
return results if return_json else True

then in mail.send()
we can have: mail.send(return_json=True)

@mymah01
Copy link
Author

mymah01 commented Sep 23, 2025

I can update to reflect proposed changes that cater for previous usage as well.

@nicholasserra
Copy link
Collaborator

I think the new change is good. Looks like tests might be broken upstream. Also I think your tests will need updated with the new changes. I'm gonna peek the test suite in master and we'll go from there. Thanks!

@nicholasserra
Copy link
Collaborator

Confirmed tests are fine in master. Looks like they're broken in here. Adding some comments on the diff.

@nicholasserra nicholasserra merged commit 1b8d0c3 into themartorana:master Oct 1, 2025
5 checks passed
@nicholasserra
Copy link
Collaborator

LGTM thanks! I'll bump and do a release

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.

2 participants