Postmark inline images with Base64 and CID
To put an image inside a Postmark HTML email, send the image bytes as a Base64 attachment and reference that attachment from the HTML. The attachment is part of the email; the <img> element does not contain the Base64 string itself.
If you already have an image file, the Image to Base64 tool can give you the raw Base64 value without uploading the file. Select raw Base64 for the API payload. A full data:image/png;base64,... URL belongs in a browser document, not in Postmark's Attachments.Content field.
The two values that must match
Postmark's official inline-image example, checked on October 8, 2026, uses a ContentID such as cid:logo001. The HTML uses the same value: <img src="cid:logo001" alt="Company logo">.
The attachment fields describe different things:
| Field | Value |
|---|---|
Name | A filename, such as logo.png |
Content | Raw Base64 of the image bytes |
ContentType | The MIME type, such as image/png |
ContentID | The CID reference used by the HTML, including cid: in Postmark's documented format |
Do not copy a different provider's attachment schema unchanged. For example, SendGrid inline images use different field names and a different convention for content_id.
Why a data URI in HtmlBody is the weaker bet
A browser renders a data: source right away, which makes the trick look safe while you are testing in a page. Mail is a different environment. Clients decide for themselves whether to honor that scheme, some sanitizers strip it, and support is uneven enough that one message renders two ways in two inboxes. Postmark accepts the payload either way, so the API response tells you nothing about the outcome.
Size compounds the problem. The encoded bytes become part of HtmlBody itself, so a large image inflates the body rather than riding along as its own part. Clients that trim long bodies can cut the payload mid-string, which leaves a broken image and no error anywhere in the delivery log. A CID attachment keeps the body small.
Build the payload in Node.js
Save this as postmark-inline.mjs. It requires Node.js 18 or later and a PNG named logo.png. Running it normally prints a reviewable payload. Passing --send makes an actual API request, so use a verified sender, the intended recipient, and a server token only when you are ready to send.
import { readFile } from "node:fs/promises";
const bytes = await readFile("logo.png");
const cid = "cid:logo001";
const payload = {
From: process.env.EMAIL_FROM || "sender@example.com",
To: process.env.EMAIL_TO || "recipient@example.com",
Subject: "Inline image example",
HtmlBody: `<p>Your image:</p><img src="${cid}" alt="Company logo">`,
TextBody: "This message includes an image in the HTML version.",
Attachments: [{
Name: "logo.png",
Content: bytes.toString("base64"),
ContentType: "image/png",
ContentID: cid
}]
};
if (!process.argv.includes("--send")) {
console.log(JSON.stringify(payload, null, 2));
} else {
const token = process.env.POSTMARK_SERVER_TOKEN;
if (!token || !process.env.EMAIL_FROM || !process.env.EMAIL_TO) {
throw new Error("Set POSTMARK_SERVER_TOKEN, EMAIL_FROM, and EMAIL_TO first.");
}
const response = await fetch("https://api.postmarkapp.com/email", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"X-Postmark-Server-Token": token
},
body: JSON.stringify(payload)
});
const result = await response.json();
if (!response.ok || result.ErrorCode !== 0) {
throw new Error(`Postmark request failed: ${JSON.stringify(result)}`);
}
console.log(result.MessageID);
}
The MIME type must match the file you read. For a JPEG, change the filename and use image/jpeg. Do not relabel JPEG bytes as PNG. Keep real tokens in environment variables rather than the source file, and review the payload before sending.
ContentID naming: the prefix belongs to the value
Postmark's documented example puts the whole prefixed string in the field, so ContentID holds cid:logo001 and the HTML holds the same characters. Exact equality is what makes the lookup work. A helper that adds cid: in one place and omits it in the other produces a message the client cannot reconcile, and clients disagree about whether to guess.
Set the value once and reuse the variable in both spots:
const cid = "cid:logo001";
const attachment = { ContentID: cid, /* Name, Content, ContentType */ };
const html = `<img src="${cid}" alt="Company logo">`;
Providers differ in what they expect here, so copy the convention from the current API reference rather than from a blog post. The Brevo attachment guide covers an endpoint whose public schema does not expose this field at all, which is the opposite failure: no naming mistake, just no supported way to set the identifier.
Raw Base64, data URI, and CID are different
Raw Base64 is the encoded file content. A data URI adds a media type and prefix, for example data:image/png;base64,.... A CID is a reference to an attachment in a MIME message.
If your upstream code returns a data URI, remove its header before placing the content in Attachments.Content. If your upstream code already returns raw Base64, use it directly. Encoding that text a second time produces Base64 of the string rather than Base64 of the original image bytes. The API payload guide explains this boundary in more detail.
Message size, and when a hosted image wins
Encoding is mechanical: three bytes become four characters, so a file of size N lands at roughly 1.33N once it is text. A 2 MB photograph therefore adds about 2.7 MB to the request, and the delivered message carries the same weight. Provider size limits apply on top of that; read the current figures instead of assuming a round number.
Past a few hundred kilobytes, hosting usually wins. A public HTTPS URL keeps the message light, lets the recipient's client cache the file, and removes the encoding step from your code. The costs are real too. Many clients withhold remote images until the recipient allows them, and the URL has to stay reachable for as long as old mail is opened. Logos and small diagrams belong in the message; photography usually belongs behind a link.
The Base64 size calculator turns a known file size into the encoded length, which makes that decision arithmetic rather than guesswork after a rejection.
A test loop that proves rendering
The API response confirms acceptance and nothing more. Rendering needs its own check, and the loop is short: send to a Gmail mailbox and to Outlook desktop, open each message's original source, then look at the picture with remote images blocked.
In the source, confirm the image part exists with the expected Content-Type, a Content-ID identical to the value in the HTML, and Content-Disposition: inline. In the rendered view with remote content disabled — the default for many recipients — a CID image should still appear, because it travels inside the message and triggers no network fetch. If the picture disappears in that state, something remote is being loaded and the message is not doing what you think. Background on how clients treat inline data is in Base64 images in HTML email.
Troubleshooting an image that does not render
Check the CID match first. Check that Content has no data: prefix, that its decoded bytes form the expected file, and that ContentType matches those bytes. Use a small image while debugging so the payload is easy to inspect.
Client behavior still matters after a valid API request. An accepted message does not prove that every mail client displayed the image. Test the actual clients your recipients use; the Outlook Base64 image guide explains why a data URI inside HTML is a separate compatibility problem.
FAQ
Can I paste a data URI directly into HtmlBody?
CID attachments are the documented pattern here. Email clients have uneven support for data URIs, so a browser preview is not a mail-client test.
Does the Postmark token belong in the browser?
No. Send through a server you control. A browser-only converter can prepare the Base64 value without holding a mail-service credential.
Will every client show the image inline?
That requires client testing. A successful API response confirms acceptance by the API, not inbox placement or rendering.
Related guides
Use SendGrid CID attachments for a provider-specific comparison, image-to-Base64 API payloads for output shapes, and Outlook image troubleshooting for client behavior.