Skip to main content

The short answer

Upload the file as base64 to attachments.upload(), then pass the returned attachment_id to messages.send(). For inbound attachments, the webhook payload includes attachment metadata — call attachments.url() to get a signed download link.

Why agents need attachments

Plain text gets you far, but real business communication requires files. Legal agents send contracts. Sales agents attach proposals. Support agents include invoices and screenshots. Finance agents forward receipts. Without attachment support, your agent hits a wall the moment a customer asks “can you send me the PDF?” Commune handles attachment storage, delivery, and retrieval so your agent code stays focused on business logic.

Sending attachments (outbound)

The workflow is two steps: upload the file, then reference it when sending.

Multiple attachments

Pass multiple attachment_id values in the array. Each file is uploaded independently, so you can reuse the same attachment across multiple emails without re-uploading.

Generating files on the fly

Agents often need to create files dynamically — CSV exports, PDF invoices, or JSON reports. Generate the content in memory, base64-encode it, and upload.

Size limits

Base64 encoding increases size by roughly 33%. A 7.5 MB file becomes ~10 MB after encoding. Keep source files under 7.5 MB to stay within the 10 MB limit.

Receiving attachments (inbound)

When someone sends your agent an email with attachments, the webhook payload includes an attachments array with metadata for each file. The actual file content is not included in the webhook — retrieve it via the API. The webhook payload looks like this:

Downloading inbound attachments

Use attachments.get() for metadata and attachments.url() for a signed download URL.

Filtering by type

Not every attachment is worth processing. Filter by MIME type and size before downloading.

Common MIME types

Messages

Full send API reference including attachments, HTML, CC/BCC, and threading.

Webhooks

Webhook payload reference for inbound emails and attachment metadata.

Sending HTML Emails

Format agent emails with HTML for professional, readable communication.
Last modified on March 19, 2026