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
10 changes: 10 additions & 0 deletions src/lettermint/endpoints/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def tag(self, tag: str) -> Self:
self._payload["tag"] = tag
return self

def tags(self, tags: list[dict[str, str]]) -> Self:
"""Set reusable name-value tags for the email."""
self._payload["tags"] = tags
return self

def send(self) -> SendEmailResponse:
"""Send the composed email.

Expand Down Expand Up @@ -555,6 +560,11 @@ def tag(self, tag: str) -> Self:
self._payload["tag"] = tag
return self

def tags(self, tags: list[dict[str, str]]) -> Self:
"""Set reusable name-value tags for the email."""
self._payload["tags"] = tags
return self

def send(self) -> Coroutine[Any, Any, SendEmailResponse]:
"""Send the composed email asynchronously.

Expand Down
52 changes: 27 additions & 25 deletions src/lettermint/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
"headers": "NotRequired[dict[str, str]]",
"metadata": "NotRequired[dict[str, str]]",
"tag": "NotRequired[str | None]",
"tags": "NotRequired[list[dict[str, Any]]]",
"settings": "NotRequired[dict[str, Any] | None]",
"html": "NotRequired[str | None]",
"text": "NotRequired[str | None]",
"attachments": "NotRequired[list[dict[str, Any]]]",
},
)

SendBatchMailRequest: TypeAlias = list[SendMailRequest]
SendBatchMailRequest: TypeAlias = list[dict[str, Any]]
AttachmentDelivery: TypeAlias = Literal["inline", "url"]
BuiltInTeamRole: TypeAlias = Literal["owner", "admin", "member"]
CursorPaginator = TypedDict(
Expand Down Expand Up @@ -150,6 +151,7 @@
"status": "Required[MessageStatus]",
"status_changed_at": "Required[str | None]",
"tag": "Required[str | None]",
"tags": "Required[list[dict[str, Any]]]",
"from_email": "Required[str]",
"from_name": "Required[str | None]",
"reply_to": "Required[list[str] | None]",
Expand Down Expand Up @@ -192,6 +194,8 @@
{
"message_id": "Required[str]",
"event": "Required[MessageEventType]",
"tag": "Required[str | None]",
"tags": "Required[list[dict[str, Any]]]",
"metadata": "Required[dict[str, Any] | None]",
"timestamp": "Required[str]",
},
Expand All @@ -212,6 +216,7 @@
"bcc": "Required[list[MessageRecipientData] | None]",
"reply_to": "Required[list[str] | None]",
"tag": "Required[str | None]",
"tags": "Required[list[dict[str, Any]]]",
"status_changed_at": "Required[str | None]",
"created_at": "Required[str]",
},
Expand All @@ -229,7 +234,6 @@

Plan: TypeAlias = Literal["free", "starter", "growth", "pro"]
ProjectAccessScope: TypeAlias = Literal["all", "selected"]
RouteType: TypeAlias = Literal["transactional", "broadcast", "inbound"]
RouteStatisticData = TypedDict(
"RouteStatisticData",
{
Expand All @@ -250,6 +254,7 @@
},
)

RouteType: TypeAlias = Literal["transactional", "broadcast", "inbound"]
RouteData = TypedDict(
"RouteData",
{
Expand Down Expand Up @@ -373,6 +378,13 @@
},
)

StatsInboundData = TypedDict(
"StatsInboundData",
{
"received": "Required[int]",
},
)

StatsTypeData = TypedDict(
"StatsTypeData",
{
Expand All @@ -382,13 +394,6 @@
},
)

StatsInboundData = TypedDict(
"StatsInboundData",
{
"received": "Required[int]",
},
)

StatsDailyData = TypedDict(
"StatsDailyData",
{
Expand Down Expand Up @@ -478,8 +483,8 @@
},
)

SuppressionScope: TypeAlias = Literal["global", "team", "project", "route"]
SuppressionReason: TypeAlias = Literal["spam_complaint", "hard_bounce", "unsubscribe", "manual"]
SuppressionScope: TypeAlias = Literal["global", "team", "project", "route"]
StoreSuppressionData = TypedDict(
"StoreSuppressionData",
{
Expand Down Expand Up @@ -644,28 +649,29 @@
},
)

UpdateRouteInboundSettingsData = TypedDict(
"UpdateRouteInboundSettingsData",
{
"inbound_domain": "NotRequired[str | None]",
"inbound_spam_threshold": "NotRequired[float | None]",
"attachment_delivery": "NotRequired[AttachmentDelivery | None]",
},
)

UpdateRouteSettingsData = TypedDict(
"UpdateRouteSettingsData",
{
"track_opens": "NotRequired[bool | None]",
"track_clicks": "NotRequired[bool | None]",
"generate_plaintext_fallback": "NotRequired[bool | None]",
"suppress_auto_responders": "NotRequired[bool | None]",
"suppress_disposable_recipients": "NotRequired[bool | None]",
"tls": "NotRequired[TlsPolicy | None]",
"disable_hosted_unsubscribe": "NotRequired[bool | None]",
"redact_email_content": "NotRequired[bool | None]",
},
)

UpdateRouteInboundSettingsData = TypedDict(
"UpdateRouteInboundSettingsData",
{
"inbound_domain": "NotRequired[str | None]",
"inbound_spam_threshold": "NotRequired[float | None]",
"attachment_delivery": "NotRequired[AttachmentDelivery | None]",
},
)

UpdateRouteData = TypedDict(
"UpdateRouteData",
{
Expand Down Expand Up @@ -860,12 +866,8 @@
"MessageEventsResponse",
{
"data": "Required[list[MessageEventData]]",
"path": "Required[str | None]",
"per_page": "Required[int]",
"next_cursor": "Required[str | None]",
"next_page_url": "Required[str | None]",
"prev_cursor": "Required[str | None]",
"prev_page_url": "Required[str | None]",
"links": "Required[list[str]]",
"meta": "Required[dict[str, Any]]",
},
)

Expand Down
7 changes: 4 additions & 3 deletions tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ def test_send_with_metadata_and_tag(self, api_token: str) -> None:
with Lettermint(api_token=api_token) as client:
client.email.from_("sender@example.com").to("recipient@example.com").subject(
"Test"
).metadata({"campaign_id": "123"}).tag("welcome").settings(
{"track_opens": False, "track_clicks": True, "tls": "enforced"}
).send()
).metadata({"campaign_id": "123"}).tag("welcome").tags(
[{"name": "campaign", "value": "welcome-v2"}]
).settings({"track_opens": False, "track_clicks": True, "tls": "enforced"}).send()

import json

body = json.loads(route.calls.last.request.content)
assert body["metadata"] == {"campaign_id": "123"}
assert body["tag"] == "welcome"
assert body["tags"] == [{"name": "campaign", "value": "welcome-v2"}]
assert body["settings"] == {
"track_opens": False,
"track_clicks": True,
Expand Down