Sending

How to send attachments and inline images

Short answer

To attach a file in Mailcandor, add an attachments list to POST /v1/emails with filename and content as base64. content_type is optional and guessed from the filename. To show an image inline, set content_id and use cid: with that id in your html. All attachments together may be up to 40 MB as base64. Attachments are not allowed in batch sends, and files cannot be fetched by URL.

Last checked 16 November 2026

Attachments travel inside the JSON as base64. Mailcandor decodes them and builds the email.

To attach a file

PDF=$(base64 < invoice-1042.pdf | tr -d '\n')

curl https://api.mailcandor.com/v1/emails \
  -H "Authorization: Bearer $MAILCANDOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "Acme <billing@acme.com>",
    "to": "sam@example.com",
    "subject": "Invoice 1042",
    "html": "<p>Your invoice is attached.</p>",
    "attachments": [
      { "filename": "invoice-1042.pdf", "content": "'"$PDF"'" }
    ]
  }'

Attachment fields

Field Required Notes
filename Yes Up to 255 characters, no slashes. Recipients see it.
content Yes The file as base64.
content_type No Guessed from the extension if left out: pdf, png, jpg, gif, csv, txt, ics and zip are known; anything else is sent as application/octet-stream.
content_id No Set it to show the file inline in the html.

To show an image inline

Give the image a content_id and refer to it with cid: in your html:

{
  "from": "Acme <hello@acme.com>",
  "to": "sam@example.com",
  "subject": "Welcome",
  "html": "<p><img src=\"cid:logo\" alt=\"Acme\" width=\"120\"></p><p>Welcome aboard.</p>",
  "attachments": [
    { "filename": "logo.png", "content": "iVBORw0KGgo...", "content_type": "image/png", "content_id": "logo" }
  ]
}

A short id like logo is fine; Mailcandor turns it into a valid Content-ID and updates the cid: reference for you.

Inline images make emails bigger. For logos used in every email, a normal https:// image URL is usually better.

In Node.js

import { readFile } from 'node:fs/promises';

const pdf = await readFile('invoice-1042.pdf');
await fetch('https://api.mailcandor.com/v1/emails', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.MAILCANDOR_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    from: 'Acme <billing@acme.com>',
    to: 'sam@example.com',
    subject: 'Invoice 1042',
    text: 'Your invoice is attached.',
    attachments: [{ filename: 'invoice-1042.pdf', content: pdf.toString('base64') }],
  }),
});

Limits

  • 40 MB in total per email, as base64. Base64 is about 4/3 the size of the file, so the raw files can add up to roughly 30 MB.
  • No attachments in batch sends.
  • No fetching by URL. Only content is accepted.
  • Over SMTP, the whole message can be up to 40 MB, and attachments are kept as sent. See Send with SMTP.

Check before you send

Files with risky names can push an email toward spam. Run the content check with the file names:

curl https://api.mailcandor.com/v1/emails/check \
  -H "Authorization: Bearer $MAILCANDOR_KEY" -H "Content-Type: application/json" \
  -d '{ "subject": "Invoice 1042", "html": "<p>Attached.</p>", "attachments": [{ "filename": "invoice-1042.pdf" }] }'

The dashboard has the same check under Check an email, with an Attachment file names field.

If it does not work

All of these return 422 invalid_attachment with field pointing at the attachment:

  • “Each attachment needs a filename without slashes, up to 255 characters.”
  • “Add the file for … as base64 in content.” The content is missing or empty.
  • “The content of … is not valid base64.” Remove line breaks and data:...;base64, prefixes.
  • “Attachments add up to more than 40 MB (as base64). Link to large files instead.”
  • “Send the file as base64 in content. Fetching files by URL is not supported yet.”
  • The inline image shows as an attachment instead: check the cid: in the html matches content_id exactly.

Questions

What is the attachment size limit?

40 MB in total per email, measured as base64, which is about a third larger than the original files. For bigger files, send a link instead.

Can I attach a file by URL?

No. Send the file itself as base64 in content. A path field is refused.

Which file types are allowed?

Mailcandor does not block types by itself. Many mailbox providers reject executable files, so send those as links.

Can I send attachments in a batch?

No. Send emails with attachments one at a time.

Related

Send with someone on your side.

Unlimited domains on every plan, a person before any block, and 3,000 emails a month free. Tell us what you send and we set you up within one business day.