Sign inGet Started

Attachments

Attach files to an email by adding an attachments array to the POST /v1/email/messages payload. Each entry has the file's bytes base64-encoded in content, plus a filename. The same array works on a batch item. Full request and response schemas are in the API reference.

A send with one attachment

await bird.email.send({
  from: "hello@yourdomain.com",
  to: ["delivered@messagebird.dev"],
  subject: "Your invoice",
  html: "<p>Thanks for your order. Your invoice is attached.</p>",
  attachments: [
    {
      filename: "invoice.pdf",
      content: "JVBERi0xLjcKJ...",
      content_type: "application/pdf",
    },
  ],
});

The CLI reads the file and base64-encodes it for you. Over the API, you supply the encoded bytes yourself. The Go SDK takes the raw bytes and encodes them on the wire.

content holds the base64-encoded raw file bytes. content_type is optional. When you omit it, we infer the MIME type from the filename extension and fall back to application/octet-stream for unrecognized extensions. Other request behavior matches sending email. Attachments do not change the 202 response, the async model, tags, or metadata.

The attachment fields

FieldTypeRequiredNotes
filenamestringyes1 to 255 characters, shown to the recipient. No line breaks or control characters.
contentstringyesBase64-encoded file bytes.
content_typestringnoMIME type. Inferred from the filename extension when omitted.
content_idstringno1 to 128 characters, [A-Za-z0-9._-]. Set it to render the file inline instead of attached.

An email can have up to 20 attachments (attachments is capped at 20 items).

Inline images

To embed an image in the HTML body instead of attaching it, give the attachment a content_id and reference it from the markup with a cid: URL:

Code example
{
  "html": "<p>Welcome aboard!</p><img src=\"cid:welcome-banner\"/>",
  "attachments": [
    {
      "filename": "banner.png",
      "content": "iVBORw0KGgoAAAANS...",
      "content_type": "image/png",
      "content_id": "welcome-banner"
    }
  ]
}

The content_id links the cid: reference to the attachment. Each inline image needs a unique content_id within the message. Duplicate values are rejected with a 422. An attachment without a content_id is delivered as a regular file attachment.

Size budget

We reject any message whose estimated generated message size exceeds 20 MB with a 413. The estimate adds the HTML body, the text body, and every attachment measured after base64 encoding. Base64 encoding inflates raw bytes by roughly 4/3. A 15 MB file fills the entire 20 MB budget by itself. Keep total raw attachment content well under 15 MB so the message bodies and MIME wrapping still fit.

Receiving servers can apply lower size limits. A message that Bird accepts can still bounce if the recipient's server rejects its size. Choose attachment sizes for the mailbox providers and organizations you send to.

For received messages, see Inbound message size.

Blocked file types

Executable and script attachments are rejected at validation time with a 422, based on either content_type or the filename extension. Blocked extensions include .exe, .dll, .msi, .bat, .cmd, .scr, .jar, .js, .vbs, .ps1, .sh, .hta, and .lnk. Equivalent MIME types such as application/x-msdownload, application/java-archive, and text/javascript are also blocked. This validation is not a virus scanner. To distribute a blocked file, host it behind a link.

In a batch

Each item in a batch can include attachments using the same field contract and per-message 20 MB budget. The batch request also enforces a serialized body size cap that base64-encoded attachments consume quickly. See batch sending for the batch-level limit and how to split large payloads.

Reading and downloading attachments

API reads do not echo attachment bytes. GET /v1/email/messages/{message_id} returns an attachments array with metadata only. Each entry includes the attachment id, filename, content_type, size (decoded bytes), and inline:

Code example
{
  "attachments": [
    {
      "id": "ea_019c...",
      "filename": "invoice.pdf",
      "content_type": "application/pdf",
      "size": 215432,
      "inline": false
    }
  ]
}

To get the raw bytes back, call GET /v1/email/messages/{message_id}/attachments/{attachment_id} (reference). It streams the file with the stored content type and a Content-Disposition header containing the filename. Attachment downloads depend on workspace storage and retention:

  • Content storage must be enabled for the workspace. With storage disabled, nothing is stored to download. See what a 202 means.
  • Attachments are retained for 30 days after the message is sent. After that, the download returns 410 Gone.

A 404 means the message has no stored content or no attachment with that ID. A 425 Too Early means the attachment is still being stored. Retry the request in a moment.

Next steps