Email Attachments
Attach files — PDFs, images, spreadsheets, and more — to any email by including an attachments array on the Send Email request. Files are Base64-encoded and sent inline with the message.
Endpoint
Attachments are part of the standard send request:
POST /v1/email/send
Attachment Object
| Field | Type | Required | Description |
|---|---|---|---|
filename | string | Yes | Name shown to the recipient (e.g. invoice-12345.pdf) |
content | string | Yes | Base64-encoded file contents |
content_type | string | Yes | MIME type (e.g. application/pdf) |
disposition | string | No | attachment (default) or inline |
content_id | string | No | CID for inline images referenced in HTML |
Limits
| Constraint | Value |
|---|---|
| Max single attachment | 10 MB |
| Max total message size | 25 MB |
| Max attachments per email | 20 |
Exceeding these returns ATTACHMENT_TOO_LARGE.
Send With an Attachment
curl -X POST https://api.afriroute.ai/api/v1/email/send \
-H "Authorization: Bearer $AFRIROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Invoice #12345",
"html": "<p>Please find your invoice attached.</p>",
"attachments": [
{
"filename": "invoice-12345.pdf",
"content": "JVBERi0xLjQKJ...",
"content_type": "application/pdf"
}
]
}'
Code Samples
send-attachment.js
import fs from 'fs';
const pdf = fs.readFileSync('invoice-12345.pdf').toString('base64');
await fetch('https://api.afriroute.ai/api/v1/email/send', {
method: 'POST',
headers: {
'Authorization': 'Bearer $AFRIROUTE_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: '[email protected]',
to: '[email protected]',
subject: 'Invoice #12345',
html: '<p>Please find your invoice attached.</p>',
attachments: [
{
filename: 'invoice-12345.pdf',
content: pdf,
content_type: 'application/pdf'
}
]
})
});
send_attachment.py
import base64
import requests
with open('invoice-12345.pdf', 'rb') as f:
pdf = base64.b64encode(f.read()).decode()
requests.post(
'https://api.afriroute.ai/api/v1/email/send',
headers={'Authorization': 'Bearer $AFRIROUTE_API_KEY'},
json={
'from': '[email protected]',
'to': '[email protected]',
'subject': 'Invoice #12345',
'html': '<p>Please find your invoice attached.</p>',
'attachments': [{
'filename': 'invoice-12345.pdf',
'content': pdf,
'content_type': 'application/pdf'
}]
}
)
Inline Images
Reference an embedded image from your HTML using a content_id and the cid: scheme.
{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Our New Logo",
"html": "<p>Check out our new logo:</p><img src=\"cid:logo\" alt=\"Logo\">",
"attachments": [
{
"filename": "logo.png",
"content": "iVBORw0KGgoAAAANS...",
"content_type": "image/png",
"disposition": "inline",
"content_id": "logo"
}
]
}
Common MIME Types
| Extension | content_type |
|---|---|
.pdf | application/pdf |
.png | image/png |
.jpg | image/jpeg |
.csv | text/csv |
.xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.zip | application/zip |
Best Practices
- Keep attachments small — link to large files instead of attaching them when possible.
- Set the correct
content_typeso clients render or download files properly. - Use inline images sparingly; many clients block remote and embedded images by default.
- Avoid executable types (
.exe,.bat) — they are commonly blocked or quarantined. - Base64 inflates size ~33% — account for this against the 25 MB total limit.
Errors
| Code | HTTP | Meaning |
|---|---|---|
ATTACHMENT_TOO_LARGE | 413 | A file or the total message exceeds limits |
INVALID_ATTACHMENT | 400 | Missing content, filename, or content_type |
BLOCKED_FILE_TYPE | 415 | The attachment type is not permitted |