Sending

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).

Inline images (and any attachment) are not supported on the batch endpoint. Use a single POST /emails when you need to embed an image.

How it works

  1. 1
    Add a cid: reference in the HTML

    Use the cid: prefix in the src of an <img> tag, e.g. <img src="cid:logo-image">. The value after cid: is an arbitrary id you choose; it must be under 128 characters.

  2. 2
    Set content_id on the attachment

    Add the same id as the content_id field 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 remote path, 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 a filename (e.g. logo.png) so receiving clients render the image correctly.
All attachment requirements and limits apply to inline images, since an inline image is just an attachment referenced from the HTML.