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);from mailsai import create_client
client = create_client() # reads MAILS_API_KEY
file = client.download_attachment(
"rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"att_01JZX8K3M9Q4P7VN2YB6RTDC0E",
)
print(len(file))curl 'https://api.mails.ai/v1/messages/received/rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E/attachments/att_01JZX8K3M9Q4P7VN2YB6RTDC0E' \
-H "Authorization: Bearer $MAILS_API_KEY"mails receiving attachment rcv_01JABC att_01JABC \
--output invoice.pdf{
"name": "mails_attachments_get",
"arguments": {
"message_id": "rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"attachment_id": "att_01JZX8K3M9Q4P7VN2YB6RTDC0E"
}
}200 application/octet-stream
The file.200 The file.
400 Invalid request — malformed JSON or a field failed
validation. Also feature_not_enabled when this
server has a feature switched off (custom domains
before they are available).
401 Missing or invalid API key.
403 The API key lacks the required scope
(insufficient_scope), or the token belongs to an
app connected by sign-in and this operation is
closed to connected apps
(connected_app_not_allowed).
404 Resource not found in this workspace, or the agent
a send names is archived (agent_archived).
500 Internal server error.Download an attachment
The file's bytes, always as a download (
Content-Disposition: attachment) with X-Content-Type-Options: nosniff.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);from mailsai import create_client
client = create_client() # reads MAILS_API_KEY
file = client.download_attachment(
"rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"att_01JZX8K3M9Q4P7VN2YB6RTDC0E",
)
print(len(file))curl 'https://api.mails.ai/v1/messages/received/rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E/attachments/att_01JZX8K3M9Q4P7VN2YB6RTDC0E' \
-H "Authorization: Bearer $MAILS_API_KEY"mails receiving attachment rcv_01JABC att_01JABC \
--output invoice.pdf{
"name": "mails_attachments_get",
"arguments": {
"message_id": "rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"attachment_id": "att_01JZX8K3M9Q4P7VN2YB6RTDC0E"
}
}200 application/octet-stream
The file.200 The file.
400 Invalid request — malformed JSON or a field failed
validation. Also feature_not_enabled when this
server has a feature switched off (custom domains
before they are available).
401 Missing or invalid API key.
403 The API key lacks the required scope
(insufficient_scope), or the token belongs to an
app connected by sign-in and this operation is
closed to connected apps
(connected_app_not_allowed).
404 Resource not found in this workspace, or the agent
a send names is archived (agent_archived).
500 Internal server error.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.
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?