Attach PDFs, images, or other files to outbound email by including an attachments array on POST /emails.
Prerequisites
- API key with
emails:sendscope - 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:
| Field | Description |
|---|---|
filename | Name shown to the recipient (1–255 chars, no / or \) |
content_type | MIME type, e.g. application/pdf |
content_b64 | Base64-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
- Sign in and open Emails (or Logs).
- Open the sent message.
- 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
- Embed images — inline images in HTML
- API reference — full request examples
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"
}
]
}'