DeckleDocs
Dashboard

Sending

Attachments

Attach files — PDFs, images, CSVs, or anything else — to a transactional email by passing them as base64-encoded content.

Add an attachments array to any send. Each item carries a filename and the file’s bytes as a base64-encoded string, and Deckle delivers it alongside your email from your verified domain.

The shape#

Each entry in the attachments array is an object with the following fields.

Attachment fields

filenamestringRequired
The name the file is delivered as, including its extension — for example invoice.pdf.
contentstring (base64)Required
The file’s bytes, base64-encoded. Items without content are dropped.
content_typestringOptional
The MIME type, such as application/pdf or image/png. Optional — Deckle infers a sensible type from the filename when omitted.

Example#

Read a file, base64-encode it, and pass it in attachments. The SDK takes the same fields as the raw JSON body.

import { readFileSync } from "node:fs";
import { Deckle } from "@deckle/sdk";

const deckle = new Deckle(process.env.DECKLE_API_KEY!);

const invoice = readFileSync("./invoice.pdf");

await deckle.emails.send({
  from: "Acme <hello@acme.com>",
  to: "jane@example.com",
  subject: "Your invoice",
  html: "<p>Thanks for your order — your invoice is attached.</p>",
  attachments: [
    {
      filename: "invoice.pdf",
      content: invoice.toString("base64"),
      content_type: "application/pdf",
    },
  ],
});

Notes#

A few things to keep in mind when attaching files:

Behavior

Base64-encode contentrequiredOptional
content must be a base64 string, not raw bytes or a file path. In Node, buffer.toString("base64") does the job.
Empty items are droppedbehaviorOptional
Any attachment whose content is missing or empty is silently skipped, so the email still sends without it.
Keep sizes reasonableguidanceOptional
Large attachments hurt deliverability and can be rejected by receiving servers. Prefer a link to a hosted file for anything sizable, and reserve attachments for small documents.

Link instead of attach when you can

For big files or ones a recipient may not expect, sending a link keeps your message light and your deliverability healthy. Reserve attachments for small, expected documents like receipts and invoices.

Next steps#