Skip to main content

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​

FieldTypeRequiredDescription
filenamestringYesName shown to the recipient (e.g. invoice-12345.pdf)
contentstringYesBase64-encoded file contents
content_typestringYesMIME type (e.g. application/pdf)
dispositionstringNoattachment (default) or inline
content_idstringNoCID for inline images referenced in HTML

Limits​

ConstraintValue
Max single attachment10 MB
Max total message size25 MB
Max attachments per email20

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​

Extensioncontent_type
.pdfapplication/pdf
.pngimage/png
.jpgimage/jpeg
.csvtext/csv
.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.zipapplication/zip

Best Practices​

  • Keep attachments small — link to large files instead of attaching them when possible.
  • Set the correct content_type so 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​

CodeHTTPMeaning
ATTACHMENT_TOO_LARGE413A file or the total message exceeds limits
INVALID_ATTACHMENT400Missing content, filename, or content_type
BLOCKED_FILE_TYPE415The attachment type is not permitted

Last Updated: May 2026 · Need help? Contact Support →