Send.dev supports file attachments for your emails. This page covers how to attach files, size limits, and supported formats.

Attaching Files

Include attachments in your email request using the attachments array:

curl -X POST https://api.send.dev/v1/emails \
  -H "Authorization: Bearer sk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "invoices@mail.yourdomain.com",
    "to": "customer@example.com",
    "subject": "Your Invoice #12345",
    "html": "<p>Please find your invoice attached.</p>",
    "attachments": [
      {
        "filename": "invoice-12345.pdf",
        "content": "JVBERi0xLjQKJeLjz9MKMyAwIG9...",
        "content_type": "application/pdf"
      }
    ]
  }'

Attachment Parameters

Attachment Object

NameTypeRequiredDescription
filenamestringrequiredName of the file as it will appear to the recipient
contentstringrequiredBase64-encoded file content
content_typestringoptionalMIME type of the file. Defaults to application/octet-stream
content_idstringoptionalContent-ID for inline attachments (use with cid: URLs)

Size Limits

LimitValue
Single attachment10 MB
Total attachments per email25 MB
Maximum attachments10 files

Large Files

For files larger than 10 MB, we recommend hosting them externally and including a download link in your email instead.

Supported File Types

Common Types

TypeExtensionMIME Type
PDF.pdfapplication/pdf
Word.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
Excel.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Images.png, .jpg, .gifimage/png, image/jpeg, image/gif
Text.txt, .csvtext/plain, text/csv
Archives.zipapplication/zip

Blocked Types

For security reasons, the following file types are blocked:

  • Executables (.exe, .bat, .cmd, .sh)
  • Scripts (.js, .vbs, .ps1)
  • Potentially malicious (.scr, .pif, .com)

Inline Attachments

For embedding images directly in your HTML email, use inline attachments with Content-ID:

{
  "from": "newsletter@mail.yourdomain.com",
  "to": "subscriber@example.com",
  "subject": "Monthly Update",
  "html": "<p>Check out our new logo:</p><img src=\"cid:logo-image\" />",
  "attachments": [
    {
      "filename": "logo.png",
      "content": "iVBORw0KGgoAAAANSUhEUgAA...",
      "content_type": "image/png",
      "content_id": "logo-image"
    }
  ]
}

The cid: URL scheme references the content_id of the attachment.

SDK Examples

Node.js

import { SendDev } from '@send.dev/sdk';
import * as fs from 'fs';

const send = new SendDev({ apiKey: process.env.SEND_API_KEY });

// Read file and convert to base64
const pdfContent = fs.readFileSync('invoice.pdf').toString('base64');

const email = await send.emails.send({
  from: 'invoices@mail.yourdomain.com',
  to: 'customer@example.com',
  subject: 'Your Invoice',
  html: '<p>Please find your invoice attached.</p>',
  attachments: [
    {
      filename: 'invoice.pdf',
      content: pdfContent,
      content_type: 'application/pdf',
    },
  ],
});

Python

import base64
from senddev import SendDev

send = SendDev(api_key="sk_live_your_api_key")

# Read file and convert to base64
with open("invoice.pdf", "rb") as f:
    pdf_content = base64.b64encode(f.read()).decode("utf-8")

email = send.emails.send(
    from_="invoices@mail.yourdomain.com",
    to="customer@example.com",
    subject="Your Invoice",
    html="<p>Please find your invoice attached.</p>",
    attachments=[
        {
            "filename": "invoice.pdf",
            "content": pdf_content,
            "content_type": "application/pdf",
        }
    ],
)

Best Practices

  1. Compress large files - Use ZIP compression for large attachments
  2. Use descriptive filenames - Help recipients identify attachments
  3. Set correct MIME types - Ensures proper handling by email clients
  4. Consider alternatives - For very large files, use download links instead
  5. Test across clients - Attachments may display differently in various email clients

Common Errors

"Attachment too large"

{
  "error": {
    "code": "attachment_too_large",
    "message": "Attachment 'file.pdf' exceeds maximum size of 10 MB",
    "max_size_bytes": 10485760
  }
}

Solution: Compress the file or host it externally.

"Blocked file type"

{
  "error": {
    "code": "blocked_file_type",
    "message": "File type '.exe' is not allowed for security reasons"
  }
}

Solution: Use a different file format or host the file externally.

"Invalid base64 content"

{
  "error": {
    "code": "invalid_attachment",
    "message": "Attachment content is not valid base64"
  }
}

Solution: Ensure the content is properly base64-encoded.

On this page