Skip to content
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Embed Images in Email from Node.js: CID Inline Attachments

Embed images in Node.js email with CID inline attachments: Nodemailer's cid field and example Resend, SendGrid, Postmark and Mailgun payloads.

To embed an image in an email from Node.js, attach the image with a Content-ID and point an <img> tag at it with src="cid:<that id>". The image travels inside the message, so a client that supports CID images can show it in the body without fetching anything from a server.

This guide covers the three ways to put an image in an HTML email, the CID method with Nodemailer, and the same message sent through the Resend, SendGrid, Postmark and Mailgun APIs with Email SDK. The provider payloads below were checked on 2026-11-27 against @opencoredev/email-sdk 3.1.0 with a stubbed fetch, so no real email was sent.

Which way should you add images to an email?

Link to a hosted image for most newsletter email, and use a CID inline attachment for small images that must travel with the message, such as a logo on a receipt or a QR code. Avoid base64 data: URIs: Gmail doesn’t display them.

Method How it works Good for Watch out for
Hosted image <img src="https://..."> Newsletters, large images Many clients hide remote images until the reader allows them
CID inline attachment Image attached with a Content-ID, <img src="cid:logo.png"> Logos, receipts, QR codes, signatures Every image adds to the message size, and some clients also list it as an attachment
Base64 data: URI Image bytes inside the src attribute Nothing in email Not displayed in Gmail

A CID image is a MIME part of the message, usually inside a multipart/related section next to the HTML, with a Content-ID header and Content-Disposition: inline. The client matches cid:logo.png in the HTML to the part whose Content-ID is logo.png. Base64 encoding adds about a third to each image’s size in transit, so keep inline images small: a logo or a QR code, not a photo gallery.

Embed an image with Nodemailer

Nodemailer takes the Content-ID in a cid field on the attachment. Install it and put a real PNG at ./emails/logo.png:

requireTLS makes Nodemailer refuse to send the password unless the server upgrades the connection with STARTTLS. Replace the sender and recipient with an address your SMTP server lets you send from and an inbox you can read. Nodemailer builds the multipart/related part for you, and the Nodemailer embedded images docs cover the cid option in full. To send the same image through a provider’s HTTP API instead, use that provider’s field for the Content-ID.

Embed images through an email API

The major email APIs accept inline images, but each names the Content-ID field differently:

Provider Field for the Content-ID Inline marker
Resend content_id on the attachment the content_id itself
SendGrid content_id disposition: "inline"
Postmark ContentID, written as "cid:logo.png" in Postmark’s docs the ContentID itself
Mailgun none; the file name is the CID an inline form part instead of attachment
Amazon SES (v2 API) ContentId ContentDisposition: "INLINE"

Two of these catch people out. Mailgun has no Content-ID field: you send the image as a form part named inline, and its file name, logo.png, is what the HTML references as cid:logo.png. Resend doesn’t accept attachments, inline images included, on its batch endpoint, so a receipt with a CID-embedded logo has to go through the single-send endpoint.

Send an inline image with Email SDK

Email SDK gives every attachment a contentId and a disposition, and adapters that support inline images turn them into their provider’s fields. Set contentId to the same value as filename so the cid: reference also works on Mailgun.

Use a sender on a domain you verified in Resend and a recipient you can read. With the SendGrid or Mailgun adapter in place of resend, the message stays the same. This is what each adapter sent for the attachment in our stubbed check (image bytes shortened):

The Postmark block was sent with contentId: "cid:logo.png". The SDK passes contentId to Postmark unchanged, and Postmark’s docs write the ContentID with a cid: prefix, so when Postmark is the adapter, use that value and keep src="cid:logo.png" in the HTML.

Mailgun got a multipart form with the image as a part named inline and file name logo.png. The SMTP adapter passes contentId to Nodemailer as cid, and the SES, Microsoft Graph, MailerSend, Mailtrap, Lettermint and Cloudflare adapters map it to their own fields as well.

Not every adapter supports inline images. Lettr and SendHeron throw an EmailValidationError before any request when an attachment has a contentId or disposition: "inline", and the Loops adapter sends the image as a regular attachment without a Content-ID. Check your adapter’s page in the adapter docs before relying on CID images, and host the image at a public URL where they aren’t supported.

Test that the image is embedded

Send the message to a local SMTP inbox such as Mailpit, then check the message source, not only how it looks. The decoded HTML part should contain src="cid:logo.png" (in the raw source, quoted-printable encoding shows it as src=3D"cid:logo.png") and the image part should carry Content-ID: <logo.png> and Content-Disposition: inline. Seeing the image in Mailpit’s viewer isn’t proof on its own, because Mailpit also loads remote images. With the defaults from the Mailpit guide, use a separate local transport with no auth and no requireTLS, because Mailpit doesn’t offer STARTTLS by default:

With Email SDK, smtp({ host: "127.0.0.1", port: 1025 }) from @opencoredev/email-sdk/smtp does the same.

If the image shows up only as an attachment, one common cause is a cid: value in the HTML that doesn’t match the attachment’s Content-ID: a typo, a missing cid: prefix in the src, or, on Mailgun, a file name that differs from the reference. Clients also differ in how they show inline parts, so send a test to the clients your users actually read mail in.

For unit tests that shouldn’t touch SMTP at all, the memory adapter records each message, attachments included, so you can assert on contentId directly.

FAQ

What does cid mean in email?

CID stands for Content-ID, a MIME header that names one part of an email. src="cid:logo.png" in the HTML tells the client to render the part whose Content-ID is logo.png in that spot.

Why does my embedded image show up as an attachment?

Usually the client couldn’t match the cid: reference to an inline part. Check that the value after cid: in the src equals the attachment’s Content-ID exactly and that the part is sent as inline: on SendGrid that needs disposition: "inline", on Mailgun the inline form part and a reference by file name. Some clients list inline images as attachments even when the match is right.

Can I embed an SVG in an email?

Support for SVG varies by email client and by how the SVG is included, so use PNG or JPEG for logos and icons unless you have tested SVG in the clients you send to.

Do inline images count against attachment size limits?

Yes. An inline image is an attachment with a different disposition, so it counts toward the provider’s message size limit after base64 encoding.

Last updated on