The Transactional resource allows you to send transactional emails using your published Brew templates. Access it via client.send.transactional.
SDK Parameter Names: The SDK uses chat_id for template IDs and variables for template data. The REST API uses different names (transactionalId and dataVariables). This documentation covers the SDK interface.
from brew_sdk.types.send import TransactionalDocumentationResponseclass TransactionalDocumentationResponse: version: Optional[str] # API version documentation: Optional[str] # Link to full docs endpoints: Optional[List[Endpoint]]class Endpoint: path: Optional[str] methods: Optional[List[str]] description: Optional[str]
When sending to multiple recipients, check each result:
Copy
Ask AI
response = client.send.transactional.send( chat_id="newsletter-template", to=["[email protected]", "[email protected]", "invalid-email"], variables={...},)# Log successful sendsfor result in response.data.results or []: if result.id: print(f"Sent to {result.email}: ID {result.id}") else: print(f"Failed for {result.email}: {result.error}")# Summaryprint(f"Total: {response.data.sent} sent, {response.data.failed} failed")
Name your templates descriptively in Brew so the IDs are easy to identify:
welcome-email
password-reset
order-confirmation
Validate variables before sending
Ensure all required template variables are present:
Copy
Ask AI
def send_order_confirmation(order): if not all([order.id, order.customer_email, order.total]): raise ValueError("Missing required order data") return client.send.transactional.send( chat_id="order-confirmation", to=order.customer_email, variables={ "orderNumber": order.id, "orderTotal": order.total, }, )
Handle failures gracefully
Always check results and handle failures:
Copy
Ask AI
response = client.send.transactional.send(...)if response.data.failed and response.data.failed > 0: # Log failures for investigation failures = [r for r in (response.data.results or []) if r.error] logger.error(f"Email failures: {failures}")
Use reply-to for support emails
Set a reply-to address so customer replies go to the right place: