From e70a88259f6c0a498ecbbc1ead4188cf3954a24b Mon Sep 17 00:00:00 2001 From: Isabella Aquino Date: Wed, 25 Nov 2026 10:22:58 -0300 Subject: [PATCH] feat(receiving): filter listed received emails by recipient and date --- resend/emails/_receiving.py | 38 +++++++++++++++++++++++++++-------- resend/version.py | 2 +- tests/emails_test.py | 31 ++++++++++++++++++++++++++++ tests/receiving_async_test.py | 18 +++++++++++++++++ 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/resend/emails/_receiving.py b/resend/emails/_receiving.py index 9de83aa..7899755 100644 --- a/resend/emails/_receiving.py +++ b/resend/emails/_receiving.py @@ -7,6 +7,7 @@ from resend.emails._received_email import (AttachmentWithSignedUrl, EmailAttachmentDetails, ListReceivedEmail, ReceivedEmail) +from resend.inboxes._query import build_inbox_query_path from resend.pagination_helper import PaginationHelper # Async imports (optional - only available with pip install resend[async]) @@ -29,6 +30,23 @@ class _ListParams(TypedDict): """ Return emails before this cursor for pagination. """ + to: NotRequired[List[str]] + """ + Recipients. Returns emails received by any of these addresses, matched + exactly and with case. Up to 20 values. + """ + start_date: NotRequired[str] + """ + Matches emails received on or after this date. Accepts a date like + ``2026-09-01`` or an ISO 8601 timestamp, in UTC unless the timestamp has + an offset. + """ + end_date: NotRequired[str] + """ + Matches emails received on or before this date. Same formats as + ``start_date``. A date covers that whole day. A timestamp is used as given. + An ``end_date`` before ``start_date`` returns a 422 validation_error. + """ class _GetParams(TypedDict): @@ -222,6 +240,10 @@ class ListParams(_ListParams): limit (NotRequired[int]): The maximum number of emails to return. Maximum 100, minimum 1. after (NotRequired[str]): Return emails after this cursor for pagination. before (NotRequired[str]): Return emails before this cursor for pagination. + to (NotRequired[List[str]]): Recipients. Returns emails received by any + of these addresses, matched exactly and with case. Up to 20 values. + start_date (NotRequired[str]): Matches emails received on or after this date. + end_date (NotRequired[str]): Matches emails received on or before this date. """ class GetParams(_GetParams): @@ -275,14 +297,14 @@ def list(cls, params: Optional[ListParams] = None) -> ListResponse: see more: https://resend.com/docs/api-reference/emails/list-received-emails Args: - params (Optional[ListParams]): The list parameters for pagination + params (Optional[ListParams]): Optional filter and pagination parameters Returns: ListResponse: A paginated list of received email objects """ - base_path = "/emails/receiving" - query_params = cast(Dict[Any, Any], params) if params else None - path = PaginationHelper.build_paginated_path(base_path, query_params) + path = build_inbox_query_path( + "/emails/receiving", cast(Dict[Any, Any], params) if params else None + ) resp = request.Request[Receiving.ListResponse]( path=path, params={}, @@ -322,14 +344,14 @@ async def list_async(cls, params: Optional[ListParams] = None) -> ListResponse: see more: https://resend.com/docs/api-reference/emails/list-received-emails Args: - params (Optional[ListParams]): The list parameters for pagination + params (Optional[ListParams]): Optional filter and pagination parameters Returns: ListResponse: A paginated list of received email objects """ - base_path = "/emails/receiving" - query_params = cast(Dict[Any, Any], params) if params else None - path = PaginationHelper.build_paginated_path(base_path, query_params) + path = build_inbox_query_path( + "/emails/receiving", cast(Dict[Any, Any], params) if params else None + ) resp = await AsyncRequest[Receiving.ListResponse]( path=path, params={}, diff --git a/resend/version.py b/resend/version.py index cb621d1..b49a80b 100644 --- a/resend/version.py +++ b/resend/version.py @@ -1,4 +1,4 @@ -__version__ = "2.55.1" +__version__ = "2.56.0" def get_version() -> str: diff --git a/tests/emails_test.py b/tests/emails_test.py index dec67ab..39e6594 100644 --- a/tests/emails_test.py +++ b/tests/emails_test.py @@ -614,6 +614,37 @@ def test_receiving_list_empty(self) -> None: assert len(emails["data"]) == 0 assert emails["has_more"] == False + def test_receiving_list_with_filters(self) -> None: + self.set_mock_json({"object": "list", "has_more": False, "data": []}) + + params: EmailsReceiving.ListParams = { + "to": ["support@acme.com", "billing@acme.com"], + "start_date": "2026-11-01", + "end_date": "2026-11-15T12:00:00Z", + "limit": 25, + "after": "cursor123", + } + resend.Emails.Receiving.list(params=params) + self.mock.assert_called_with( + url="https://api.resend.com/emails/receiving" + "?to=support%40acme.com%2Cbilling%40acme.com" + "&start_date=2026-11-01&end_date=2026-11-15T12%3A00%3A00Z" + "&limit=25&after=cursor123" + ) + + def test_receiving_list_omits_unset_filters(self) -> None: + self.set_mock_json({"object": "list", "has_more": False, "data": []}) + + resend.Emails.Receiving.list(params={"to": ["support@acme.com"]}) + self.mock.assert_called_with( + url="https://api.resend.com/emails/receiving?to=support%40acme.com" + ) + + resend.Emails.Receiving.list(params={"limit": 10, "before": "cursor123"}) + self.mock.assert_called_with( + url="https://api.resend.com/emails/receiving?limit=10&before=cursor123" + ) + def test_should_receiving_list_raise_exception_when_no_content(self) -> None: self.set_mock_json(None) with self.assertRaises(NoContentError): diff --git a/tests/receiving_async_test.py b/tests/receiving_async_test.py index ff210a8..e6b0d80 100644 --- a/tests/receiving_async_test.py +++ b/tests/receiving_async_test.py @@ -109,6 +109,24 @@ async def test_receiving_list_async(self) -> None: assert len(emails["data"]) == 1 assert emails["data"][0]["id"] == "67d9bcdb-5a02-42d7-8da9-0d6feea18cff" + async def test_receiving_list_async_with_filters(self) -> None: + self.set_mock_json({"object": "list", "has_more": False, "data": []}) + + params: EmailsReceiving.ListParams = { + "to": ["support@acme.com", "billing@acme.com"], + "start_date": "2026-11-01", + "end_date": "2026-11-15T12:00:00Z", + "limit": 25, + "after": "cursor123", + } + await resend.Emails.Receiving.list_async(params=params) + self.mock.assert_called_with( + url="https://api.resend.com/emails/receiving" + "?to=support%40acme.com%2Cbilling%40acme.com" + "&start_date=2026-11-01&end_date=2026-11-15T12%3A00%3A00Z" + "&limit=25&after=cursor123" + ) + async def test_should_list_receiving_async_raise_exception_when_no_content( self, ) -> None: