Skip to main content

send_email

Sends a transactional email via the OpenCDP Gateway.

Usage​

from cdp_client.models import EmailPayload
await client.send_email(payload: EmailPayload)

EmailPayload​

FieldTypeDescription
tostrRecipient email address.
identifiersIdentifiersUser identifiers for tracking.
transactional_message_idstrTemplate ID from the dashboard.
message_dataDict[str, Any]Variables for template substitution.
subjectstrOptional: Email subject (overrides template).
from_strOptional: Sender email (overrides template).
bodystrOptional: Raw HTML body.
attachmentsDict[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.