Skip to content
Dashboard

Email guides

Send email

Compose messages, preserve reply threads, attach files, and use stable request identifiers.

On this page

Basic send#

python
result = mail.send_mail(
    to="recipient@example.com",
    subject="Order status",
    body="Your order has shipped.",
    correlation_id="order-4421",
    idempotency_key="order-4421-shipped",
)
print(result["message_id"], result["status"])

to is required. Subject and body default to empty strings. Use cc and bcc for lists of additional recipients on unencrypted sends. A successful result acknowledges the outbound operation; delivery and recipient processing happen separately.

Tracking keys#

FieldHow to use it
correlation_idUse one workflow identifier across related messages. The server may generate one if omitted.
idempotency_keyReuse the same value and logical payload when retrying. Persist the response before scheduling more work.
message_id / thread_root_idSave the returned outbound record and thread identifiers; do not assume they identify an incoming reply.
headersOptional protocol headers retain their exact spelling. Prefer the named SDK arguments for tracking fields.

After a timeout, inspect stored records before sending again. Duplicate handling depends on the request and receiving path; independently deduplicate application actions. See retry behavior.

Attachments on plain sends#

python
from assmbl import OutboundAttachment

result = mail.send_mail(
    to="recipient@example.com",
    subject="Report",
    body="The report is attached.",
    attachments=[OutboundAttachment(
        data=b"Order,Status\n4421,Shipped\n",
        display_name="report.csv",
        content_type="text/csv",
    )],
)

The SDK uploads file bytes and sends attachment references. To use a local file, provide path instead of data. See attachment readiness, access, and encryption.

Replies and JSON bodies#

Use the original RFC message identifier and reference history when replying. This fragment assumes an incoming message you have selected:

python
import json

message_id = "msg-REPLACE-WITH-INCOMING-ID"
message = mail.get_message(message_id)
metadata = message.get("metadata") or {}
reply_to_id = metadata.get("MessageID")
if not reply_to_id:
    raise ValueError("The incoming message has no RFC message identifier")

mail.send_mail(
    to=metadata["Sender"],
    subject="Re: " + metadata.get("SubjectSnippet", ""),
    body=json.dumps({"status": "received"}),
    in_reply_to=reply_to_id,
    references=[reply_to_id],
)

body is text; serialize application JSON explicitly and validate it when reading. Encryption flags default to false. Configure encryption before enabling them. Paid replies and usage belong to the optional marketplace workflow.