Email Templates (Python)
OpenCDP allows you to send transactional emails using pre-defined templates from your dashboard.
Sending a Template Email
Specify the transactional_message_id and provide message_data for template variables.
from cdp_client.client import CDPClient
from cdp_client.models import EmailPayload, Identifiers
async def send_welcome(client: CDPClient):
payload = EmailPayload(
to="[email protected]",
identifiers=Identifiers(id="user_123"),
# The ID from your OpenCDP dashboard
transactional_message_id="welcome_v2",
# Variables to fill {{firstName}} in the template
message_data={
"firstName": "Developer",
"activation_link": "https://example.com/activate"
}
)
await client.send_email(payload)
Sending Raw HTML
If you prefer to send custom content without a pre-defined template:
async def send_report(client: CDPClient):
payload = EmailPayload(
to="[email protected]",
from_="[email protected]",
subject="Monthly Performance",
body="<h1>Report Content</h1><p>Your performance was great!</p>",
identifiers=Identifiers(email="[email protected]")
)
await client.send_email(payload)