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

const client = createClient(); // reads MAILS_API_KEY

const result = await client.drafts.attachments.add(
  "dft_01JZX8K3M9Q4P7VN2YB6RTDC0E",
  {
    filename: "order-10473.pdf",
    content_type: "application/pdf",
    size: 184320,
  },
);
console.log(result);
{
  "id": "dfa_01JZX8K3M9Q4P7VN2YB6RTDC0E",
  "filename": "<filename>",
  "content_type": "<content_type>",
  "size": 0,
  "status": "uploading",
  "chunk_bytes": 0,
  "chunk_count": 0,
  "from_message_id": "<from_message_id>",
  "created_at": "2026-10-04T12:00:00.000Z",
  "storage": { "used_bytes": 0, "limit_bytes": 0 }
}

Add a file to a draft

Declares a file and answers how to send it: put each chunk with PUT /v1/drafts/{id}/attachments/{attachment_id}/chunks/{index}.
POST/v1/drafts/{id}/attachmentsscope · manage or draft
import { createClient } from "@mailsai/sdk";

const client = createClient(); // reads MAILS_API_KEY

const result = await client.drafts.attachments.add(
  "dft_01JZX8K3M9Q4P7VN2YB6RTDC0E",
  {
    filename: "order-10473.pdf",
    content_type: "application/pdf",
    size: 184320,
  },
);
console.log(result);
{
  "id": "dfa_01JZX8K3M9Q4P7VN2YB6RTDC0E",
  "filename": "<filename>",
  "content_type": "<content_type>",
  "size": 0,
  "status": "uploading",
  "chunk_bytes": 0,
  "chunk_count": 0,
  "from_message_id": "<from_message_id>",
  "created_at": "2026-10-04T12:00:00.000Z",
  "storage": { "used_bytes": 0, "limit_bytes": 0 }
}

Path Parameters

idstringrequired

Draft id.

Body Parameters

filenamestringrequired

The file's name, as the recipient sees it.

content_typestring

The file's MIME type, such as application/pdf. Left out, application/octet-stream.

sizeintegerrequired

The file's size in bytes, at least 1. A draft's files can come to 25 MB together, and 10 files at most.

A draft can carry 10 files, 25 MB together (400 invalid_field), and a workspace's drafts can hold 200 MB of files on Free, 2 GB on Pro and 10 GB on Scale (402 resource_cap_exceeded), counted from when a file is added until its draft is sent or deleted. A file whose upload does not finish is deleted after an hour. The answer's storage says how much of that room is used. Scheduled drafts need the send scope; a test key cannot change a draft a live key made (403 live_mode_required).

Response

idstring

File id (dfa_…).

filenamestring

The file's name, as the recipient sees it.

content_typestring

The file's MIME type.

sizeinteger

The file's size in bytes.

statusstring

uploading: some chunks have not arrived, and the draft cannot be sent or scheduled. ready: every chunk is in.

One of: uploading, ready

chunk_bytesinteger

How long each chunk is, except the last, in bytes: 3 MiB.

chunk_countinteger

How many chunks the file is sent in, numbered from 0. 0 on a forward's file, which is read from the email.

from_message_idstring

On a forward's file: the received message it is read from when the draft is sent. Absent on a file that was uploaded.

created_atstring

When the file was added.

storageobject

On the answer to adding a file: how much room the workspace's drafts have left for files. Absent otherwise.

Show propertiesHide properties
used_bytesinteger

What the workspace's drafts hold of files, in bytes, this one included. A forward's own files are read from the email and do not count.

limit_bytesinteger

What the plan lets them hold, in bytes: 200 MB on Free, 2 GB on Pro, 10 GB on Scale.

Was this page helpful?