Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions resend/emails/_receiving.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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={},
Expand Down Expand Up @@ -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={},
Expand Down
2 changes: 1 addition & 1 deletion resend/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.55.1"
__version__ = "2.56.0"


def get_version() -> str:
Expand Down
31 changes: 31 additions & 0 deletions tests/emails_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions tests/receiving_async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down