Skip to content
Open
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
3 changes: 3 additions & 0 deletions examples/async/domains_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ async def main() -> None:
"name": "example.com",
"region": "us-east-1",
"custom_return_path": "outbound",
"tls": "enforced",
"capabilities": {"sending": "enabled", "receiving": "enabled"},
}
domain: resend.Domains.CreateDomainResponse = await resend.Domains.create_async(
params=create_params
)
print(domain)
print(f"Capabilities: {domain['capabilities']}")

retrieved: resend.Domain = await resend.Domains.get_async(domain_id=domain["id"])
if retrieved["records"] is not None:
Expand Down
3 changes: 3 additions & 0 deletions examples/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
"name": "example.com",
"region": "us-east-1",
"custom_return_path": "outbound",
"tls": "enforced",
"capabilities": {"sending": "enabled", "receiving": "enabled"},
}
domain: resend.Domains.CreateDomainResponse = resend.Domains.create(
params=create_params
)
print(domain)
print(f"Capabilities: {domain['capabilities']}")

retrieved: resend.Domain = resend.Domains.get(domain_id=domain["id"])
if retrieved["records"] is not None:
Expand Down
4 changes: 3 additions & 1 deletion resend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .contacts.imports._contact_imports import ContactImports
from .contacts.segments._contact_segment import ContactSegment
from .contacts.segments._contact_segments import ContactSegments
from .domains._domain import Domain
from .domains._domain import Domain, DomainCapabilities, DomainCapabilityStatus
from .domains._domains import Domains
from .domains.claims._domain_claim import DomainClaim, DomainClaimRecord
from .domains.claims._domain_claims import DomainClaims
Expand Down Expand Up @@ -218,6 +218,8 @@
"ContactTopic",
"TopicSubscriptionUpdate",
"Domain",
"DomainCapabilities",
"DomainCapabilityStatus",
"DomainClaim",
"DomainClaimRecord",
"ApiKey",
Expand Down
19 changes: 18 additions & 1 deletion resend/domains/_domain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from typing import List, Union

from typing_extensions import NotRequired, TypedDict
from typing_extensions import Literal, NotRequired, TypedDict

from resend.domains._record import Record

DomainCapabilityStatus = Literal["enabled", "disabled"]


class DomainCapabilities(TypedDict):
sending: DomainCapabilityStatus
"""
Whether the domain can send emails.
"""
receiving: DomainCapabilityStatus
"""
Whether the domain can receive emails.
"""


class Domain(TypedDict):
id: str
Expand Down Expand Up @@ -46,3 +59,7 @@ class Domain(TypedDict):
"""
The custom subdomain used for click and open tracking links (e.g., "links").
"""
capabilities: NotRequired[DomainCapabilities]
"""
The sending and receiving capabilities of the domain.
"""
44 changes: 43 additions & 1 deletion resend/domains/_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from resend import request
from resend._base_response import BaseResponse
from resend.domains._domain import Domain
from resend.domains._domain import (Domain, DomainCapabilities,
DomainCapabilityStatus)
from resend.domains._record import Record
from resend.domains.claims._domain_claims import DomainClaims
from resend.pagination_helper import PaginationHelper
Expand Down Expand Up @@ -78,6 +79,7 @@ class CreateDomainResponse(BaseResponse):
open_tracking (bool): Whether open tracking is enabled
click_tracking (bool): Whether click tracking is enabled
tracking_subdomain (str): The custom subdomain for tracking links
capabilities (DomainCapabilities): The sending and receiving capabilities of the domain
"""

id: str
Expand Down Expand Up @@ -116,6 +118,10 @@ class CreateDomainResponse(BaseResponse):
"""
The custom subdomain used for click and open tracking links (e.g., "links")
"""
capabilities: NotRequired[DomainCapabilities]
"""
The sending and receiving capabilities of the domain
"""

class UpdateDomainResponse(BaseResponse):
"""Response from updating a domain."""
Expand All @@ -136,6 +142,23 @@ class RemoveDomainResponse(BaseResponse):
id: str
deleted: bool

class CapabilitiesParams(TypedDict, total=False):
"""
CapabilitiesParams sets which capabilities of a domain are enabled.
At least one capability must stay enabled.
"""

sending: DomainCapabilityStatus
"""
Enable or disable sending emails from this domain.
On create, the default is "enabled".
"""
receiving: DomainCapabilityStatus
"""
Enable or disable receiving emails to this domain.
On create, the default is "disabled".
"""

class UpdateParams(TypedDict):
id: str
"""
Expand Down Expand Up @@ -164,6 +187,10 @@ class UpdateParams(TypedDict):
"""
The custom subdomain used for click and open tracking links (e.g., "links").
"""
capabilities: NotRequired["Domains.CapabilitiesParams"]
"""
The capabilities to change. A capability that is left out keeps its current value.
"""

class CreateParams(TypedDict):
name: str
Expand Down Expand Up @@ -193,6 +220,21 @@ class CreateParams(TypedDict):
"""
Track the open rate of each email.
"""
tls: NotRequired[TlsOptions]
"""
default: "opportunistic"
opportunistic: Opportunistic TLS means that it always attempts to make a
secure connection to the receiving mail server.
If it can't establish a secure connection, it sends the message unencrypted.

enforced: Enforced TLS on the other hand, requires that the email
communication must use TLS no matter what.
If the receiving server does not support TLS, the email will not be sent.
"""
capabilities: NotRequired["Domains.CapabilitiesParams"]
"""
The capabilities to enable for the domain.
"""

@classmethod
def create(cls, params: CreateParams) -> CreateDomainResponse:
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.54.0"
__version__ = "2.54.1"


def get_version() -> str:
Expand Down
130 changes: 130 additions & 0 deletions tests/domains_async_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import AsyncMock

import pytest
from typing_extensions import assert_type

Expand Down Expand Up @@ -355,3 +357,131 @@ async def test_should_verify_domains_async_raise_exception_when_no_content(
_ = await resend.Domains.verify_async(
domain_id="d91cd9bd-1176-453e-8fc1-35364d380206"
)

async def test_domains_create_async_returns_capabilities(self) -> None:
self.set_mock_json(
{
"id": "4dd369bc-aa82-4ff3-97de-514ae3000ee0",
"name": "example.com",
"created_at": "2026-03-28 17:12:02.059593+00",
"status": "not_started",
"capabilities": {"sending": "enabled", "receiving": "enabled"},
"records": [],
"region": "us-east-1",
}
)

params: resend.Domains.CreateParams = {
"name": "example.com",
"capabilities": {"receiving": "enabled"},
}
domain = await resend.Domains.create_async(params)
assert_type(domain["capabilities"], resend.DomainCapabilities)
assert domain["capabilities"]["sending"] == "enabled"
assert domain["capabilities"]["receiving"] == "enabled"

async def test_domains_get_async_returns_capabilities(self) -> None:
self.set_mock_json(
{
"object": "domain",
"id": "d91cd9bd-1176-453e-8fc1-35364d380206",
"name": "example.com",
"status": "not_started",
"created_at": "2026-04-26 20:21:26.347412+00",
"region": "us-east-1",
"capabilities": {"sending": "enabled", "receiving": "disabled"},
"records": [],
}
)

domain = await resend.Domains.get_async(
domain_id="d91cd9bd-1176-453e-8fc1-35364d380206"
)
assert_type(domain["capabilities"], resend.DomainCapabilities)
assert domain["capabilities"]["sending"] == "enabled"
assert domain["capabilities"]["receiving"] == "disabled"

async def test_domains_list_async_returns_capabilities(self) -> None:
self.set_mock_json(
{
"object": "list",
"has_more": False,
"data": [
{
"id": "d91cd9bd-1176-453e-8fc1-35364d380206",
"name": "example.com",
"status": "not_started",
"created_at": "2026-04-26 20:21:26.347412+00",
"region": "us-east-1",
"capabilities": {
"sending": "enabled",
"receiving": "disabled",
},
}
],
}
)

domains = await resend.Domains.list_async()
assert_type(domains["data"][0]["capabilities"], resend.DomainCapabilities)
assert domains["data"][0]["capabilities"]["sending"] == "enabled"
assert domains["data"][0]["capabilities"]["receiving"] == "disabled"


class TestDomainsRequestBodyAsync:
def setup_method(self) -> None:
self.previous_api_key = resend.api_key
resend.api_key = "re_123"
self.mock_client = AsyncMock()
self.mock_client.request.return_value = (
b'{"object": "domain", "id": "479e3145-dd38-476b-932c-529ceb705947"}',
200,
{"content-type": "application/json"},
)
self.previous_async_http_client = resend.default_async_http_client
resend.default_async_http_client = self.mock_client

def teardown_method(self) -> None:
resend.default_async_http_client = self.previous_async_http_client
resend.api_key = self.previous_api_key

async def test_create_async_sends_tls_and_capabilities(self) -> None:
params: resend.Domains.CreateParams = {
"name": "example.com",
"tls": "enforced",
"capabilities": {"sending": "enabled", "receiving": "enabled"},
}
self.mock_client.request.return_value = (
b'{"id": "4dd369bc-aa82-4ff3-97de-514ae3000ee0", "name": "example.com",'
b' "created_at": "2026-03-28 17:12:02.059593+00", "status": "not_started",'
b' "region": "us-east-1", "records": [],'
b' "capabilities": {"sending": "enabled", "receiving": "enabled"}}',
200,
{"content-type": "application/json"},
)
domain = await resend.Domains.create_async(params)
assert domain["capabilities"]["receiving"] == "enabled"

_, kwargs = self.mock_client.request.call_args
assert kwargs["method"] == "post"
assert kwargs["url"] == f"{resend.api_url}/domains"
assert kwargs["json"] == {
"name": "example.com",
"tls": "enforced",
"capabilities": {"sending": "enabled", "receiving": "enabled"},
}

async def test_update_async_sends_a_single_capability(self) -> None:
params: resend.Domains.UpdateParams = {
"id": "479e3145-dd38-476b-932c-529ceb705947",
"capabilities": {"receiving": "enabled"},
}
await resend.Domains.update_async(params)

_, kwargs = self.mock_client.request.call_args
assert kwargs["method"] == "patch"
assert (
kwargs["url"]
== f"{resend.api_url}/domains/479e3145-dd38-476b-932c-529ceb705947"
)
assert kwargs["json"]["capabilities"] == {"receiving": "enabled"}
Loading
Loading