Embed inline images
Reference an attachment from your HTML with a cid: source so an image renders inline in the body of the email.
You can embed an image directly in the HTML body of an email instead of hosting it on an external server. The image travels with the message as an attachment, and the HTML references it by a content id (cid).
How it works
- 1Add a cid: reference in the HTML
Use the
cid:prefix in thesrcof an<img>tag, e.g.<img src="cid:logo-image">. The value aftercid:is an arbitrary id you choose; it must be under 128 characters. - 2Set content_id on the attachment
Add the same id as the
content_idfield of the matching attachment object. MailBlastr links the<img>to the attachment by this id when it assembles the message.
Remote image
Reference a hosted image with path. MailBlastr fetches and base64-encodes it for you at send time (the fetch is SSRF-guarded), so you do not need to encode anything yourself.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.emails.send({
"from": "Acme <hello@yourdomain.com>",
"to": ["delivered@example.com"],
"subject": "Thank you for contacting us",
"html": "<p>Here is our <img src=\"cid:logo-image\"/> inline logo</p>",
"attachments": [
{
"path": "https://files.example.com/logo.png",
"filename": "logo.png",
"content_id": "logo-image"
}
]
});
console.log({ data, error });Local image
To inline a file from disk, read it and base64-encode the bytes into the content field, then point the content_id at the matching cid.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.emails.send({
"from": "Acme <hello@yourdomain.com>",
"to": ["delivered@example.com"],
"subject": "Thank you for contacting us",
"html": "<p>Here is our <img src=\"cid:logo-image\"/> inline logo</p>",
"attachments": [
{
"content": "iVBORw0KGgoAAAANS...base64...",
"filename": "logo.png",
"content_type": "image/png",
"content_id": "logo-image"
}
]
});
console.log({ data, error });Things to keep in mind
- When you inline a local image you must base64-encode it yourself in
content. With a remotepath, MailBlastr fetches and encodes it for you. - Inline images increase the total size of the email — they count toward the per-email (40 MB) size limit.
- Some clients (especially webmail) may reject or strip inline images. Where it matters, host the image and link to it normally instead.
- Set a
content_type(e.g.image/png) or afilename(e.g.logo.png) so receiving clients render the image correctly.