send_email
Sends a transactional email via the OpenCDP Gateway.
Usage
from cdp_client.models import EmailPayload
await client.send_email(payload: EmailPayload)
EmailPayload
| Field | Type | Description |
|---|---|---|
to | str | Recipient email address. |
identifiers | Identifiers | User identifiers for tracking. |
transactional_message_id | str | Template ID from the dashboard. |
message_data | Dict[str, Any] | Variables for template substitution. |
subject | str | Optional: Email subject (overrides template). |
from_ | str | Optional: Sender email (overrides template). |
body | str | Optional: Raw HTML body. |
attachments | Dict[str, str] | Optional: Filename to base64 content. Max 5 files, 2 MB decoded in total. |
Example
from cdp_client.models import EmailPayload, Identifiers
payload = EmailPayload(
to="[email protected]",
identifiers=Identifiers(id="u_001"),
transactional_message_id="welcome_v1",
message_data={"first_name": "User"}
)
await client.send_email(payload)
Attachments
attach() and attach_file() base64-encode the content for you:
payload = EmailPayload(
to="[email protected]",
identifiers=Identifiers(id="u_001"),
transactional_message_id="invoice_v1",
)
payload.attach_file("./invoice.pdf") # named "invoice.pdf"
payload.attach("notes.txt", "Plain text content") # strings are base64-encoded by default
payload.attach("report.csv", existing_base64, encode=False) # already base64, sent as-is
await client.send_email(payload)
send_email validates attachments before sending: at most 5 files, at most 2 MB decoded in total, filenames without /, \ or .., and non-empty base64 content. The content type is inferred from the file extension. Invalid attachments raise CDPValidationError when fail_on_exception=True; otherwise the error is logged and nothing is sent.