Skip to main content
import { createClient } from "@mailsai/sdk";

const client = createClient(); // reads MAILS_API_KEY

const file = await client.received.attachments.download(
  "rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
  "att_01JZX8K3M9Q4P7VN2YB6RTDC0E",
);
console.log(file.byteLength);
200 application/octet-stream
The file.

Download an attachment

The file's bytes, always as a download (Content-Disposition: attachment) with X-Content-Type-Options: nosniff.
GET/v1/messages/received/{id}/attachments/{attachment_id}scope · read
import { createClient } from "@mailsai/sdk";

const client = createClient(); // reads MAILS_API_KEY

const file = await client.received.attachments.download(
  "rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
  "att_01JZX8K3M9Q4P7VN2YB6RTDC0E",
);
console.log(file.byteLength);
200 application/octet-stream
The file.

Path Parameters

idstringrequired

Received message id (rcv_…).

attachment_idstringrequired

Attachment id (att_…).

Query Parameters

inlinestring

1 to display a safe image inline instead of downloading it.

One of: 1

Content-Type is the declared type when it is on a safe list, else application/octet-stream; HTML and SVG are never served as themselves. ?inline=1 asks for inline display, granted only for PNG, JPEG, GIF, WebP, AVIF and BMP images.

Was this page helpful?