Attachments

Send files with POST /emails using base64-encoded content—up to 5 files and 5 MiB total per message.

Attach PDFs, images, or other files to outbound email by including an attachments array on POST /emails.

Prerequisites

  • API key with emails:send scope
  • File content encoded as base64 (content_b64)
  • Total decoded size ≤ 5 MiB across all attachments
  • At most 5 attachments per message

Step-by-step

1. Read and encode the file

On your server, read the file bytes and base64-encode them. Never expose raw file paths to the client—encode on the backend.

2. Build the attachment object

Each attachment requires:

FieldDescription
filenameName shown to the recipient (1–255 chars, no / or \)
content_typeMIME type, e.g. application/pdf
content_b64Base64-encoded file contents

3. Send the email

Include attachments alongside to, subject, and html or text:

{
  "to": ["user@example.com"],
  "subject": "Your invoice",
  "html": "<p>Please find your invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "content_type": "application/pdf",
      "content_b64": "JVBERi0xLjQK..."
    }
  ]
}

4. Verify in the dashboard

  1. Sign in and open Emails (or Logs).
  2. Open the sent message.
  3. Confirm attachment metadata (filename, content_type) appears on the detail view.

Screenshot placeholder: Save dashboard captures to public/docs/images/sending/attachments/ and reference them in future edits.

Limitations

  • Inline base64 only — remote attachment URLs (pass a URL instead of bytes) are not supported yet.
  • 5 MiB total decoded size per message.
  • No download API — attachment bytes are not re-served via a separate REST endpoint; metadata appears on GET /emails/{id}.

Related

Example request

curl -sS -X POST "https://api.piisend.com/api/v1/emails" \
  -H "Authorization: Bearer $PIISEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": ["user@example.com"],
    "subject": "Your invoice",
    "html": "<p>Invoice attached.</p>",
    "attachments": [
      {
        "filename": "invoice.pdf",
        "content_type": "application/pdf",
        "content_b64": "BASE64_ENCODED_BYTES"
      }
    ]
  }'

Documentation

Integrate with the REST API

Quickstart, API reference, and webhooks—everything you need to send from your app.