Receiving

How to download attachments from received emails

Short answer

Attachments on received emails are listed in the email.received webhook and in GET /v1/emails/receiving/{id}. To download one, call GET /v1/emails/receiving/{id}/attachments/{attachmentId} with a full-access key. It returns a signed download_url that works for one hour without an API key, plus its expires_at. Ask again for a fresh link after it expires. In the dashboard, open the email under Received and select the file name.

Last checked 16 November 2026

Mailcandor keeps every file from a received email. You fetch a short-lived link and download from it.

What you get about each attachment

In the email.received webhook and in every received email from the API:

{
  "id": "a4f2c1d0-5b6e-4f7a-8c9d-0e1f2a3b4c5d",
  "filename": "proof.pdf",
  "content_type": "application/pdf",
  "content_disposition": "attachment",
  "content_id": null,
  "size": 48213
}
  • content_disposition is attachment for attached files and usually inline for images shown in the body.
  • content_id is set for inline parts; the HTML refers to it as cid:....
  • size is in bytes.
  • Files without a name are called attachment-0, attachment-1 and so on.

To download in the dashboard

  1. Open Received and select the email.
  2. Under Attachments, select the file name.

The link works for 30 minutes.

To download with the API

Use a full-access key.

1. Get the link:

curl https://api.mailcandor.com/v1/emails/receiving/EMAIL_ID/attachments/ATTACHMENT_ID \
  -H "Authorization: Bearer $MAILCANDOR_KEY"
{
  "object": "attachment",
  "id": "a4f2c1d0-5b6e-4f7a-8c9d-0e1f2a3b4c5d",
  "filename": "proof.pdf",
  "content_type": "application/pdf",
  "content_disposition": "attachment",
  "content_id": null,
  "size": 48213,
  "download_url": "https://.../inbound/attachments/a4f2c1d0-...?expires=...&signature=...",
  "expires_at": "2026-11-15T11:20:00Z"
}

2. Download the file, no API key needed:

curl -L -o proof.pdf "DOWNLOAD_URL"

To get links for every file on an email at once:

curl https://api.mailcandor.com/v1/emails/receiving/EMAIL_ID/attachments \
  -H "Authorization: Bearer $MAILCANDOR_KEY"

It returns {"object": "list", "data": [...]}, each with its own download_url.

In Node.js

const headers = { Authorization: `Bearer ${process.env.MAILCANDOR_KEY}` };
const base = 'https://api.mailcandor.com/v1/emails/receiving';

const { data } = await (await fetch(`${base}/${emailId}/attachments`, { headers })).json();
for (const file of data) {
  if (file.content_disposition === 'inline') continue; // skip logos and signatures
  const bytes = Buffer.from(await (await fetch(file.download_url)).arrayBuffer());
  await saveFile(file.filename, file.content_type, bytes);
}

Handle files safely

Received files come from anyone who can email you.

  • Check the Virus check verdict on the email in the dashboard before trusting files.
  • Do not trust filename for paths on your server. Generate your own name.
  • Do not trust content_type alone. Check the file itself before you process it.
  • Do not share download_url links publicly. Anyone with a link can download the file until it expires.

If it does not work

  • The link answers 403: it expired or was changed. Ask the API for a new one.
  • 404 not_found “No attachment with this id on that email.”: the attachment id belongs to a different email. Use the ids from that email’s attachments.
  • 403 restricted_api_key: use a full-access key.
  • A file you expected is missing: some mail apps put content in the body instead of as a file. Check html and text from GET /v1/emails/receiving/{id}.

Questions

How long does a download link work?

One hour from the API call. Links from the dashboard work for 30 minutes. Ask again for a new one at any time.

Do I need my API key to download the file?

Not for the download_url itself; it is signed. You need a full-access key to get the link.

Are inline images listed as attachments?

Yes. Each file part is listed, with content_disposition and content_id so you can tell inline images from attached files.

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.