_emailmd_

CLI

Render markdown to email-safe HTML from the command line.

emailmd ships with a built-in CLI.

Install

If emailmd is already a project dependency, you can run it via npx:

npx emailmd input.md

To install it as a global command:

npm install -g emailmd

Usage

emailmd [file] [options]
emailmd lint [file] [options]
emailmd mcp [options]

If no file is given, the CLI reads from stdin. The lint command checks the email instead of rendering it; see Linting below. The mcp command runs the MCP server for AI clients; see MCP Server below.

Options

OptionDescription
-o, --output <f>Write output to a file instead of stdout
-t, --textOutput plain text instead of HTML
-m, --minifyMinify the HTML output
-b, --beautifyPretty-print the HTML output (ignored with -m)
--escape-htmlEscape raw HTML for untrusted input. See Raw HTML.
-p, --partials <path>Partials for ::: include <name>: a directory of .md files or a single file. Repeatable.
--strictlint only: exit non-zero on suggestions as well
-h, --helpShow help
-v, --versionShow version number

Examples

Render a markdown file to HTML:

emailmd input.md

Write the output to a file:

emailmd input.md -o output.html

Get the plain text version (for the text/plain MIME part):

emailmd input.md --text

Minify the HTML output (useful for staying under Gmail's 102KB clip limit):

emailmd input.md --minify -o output.html

Pretty-print the HTML output (handy for reading it straight in the terminal):

emailmd input.md --beautify

Escape raw HTML when the source is untrusted, so raw tags render as text instead of markup. This also drops unsafe {attr=…} attributes and escapes HTML inside template tags. See Raw HTML:

emailmd untrusted.md --escape-html -o safe.html

Load partials from a directory. Each .md file becomes a partial named after its path relative to the directory, so partials/blocks/legal.md is included as ::: include blocks/legal. Individual files work too (named by basename), and the flag is repeatable with later paths winning on name collisions:

emailmd input.md --partials ./partials
emailmd input.md -p ./partials -p ./extra/legal.md

Pipe from another command:

echo "# Hello" | emailmd
curl -s https://example.com/template.md | emailmd -o email.html

Linting

emailmd lint checks the email for deliverability, accessibility, and readability problems instead of rendering it: missing alt text, http:// links, Gmail's 102KB clip limit, generic link text, spam-trigger phrases, and more. See Linting for the full rule list.

emailmd lint input.md
emailmd lint input.md --partials ./partials
   5  warning     Image is missing alt text — screen readers and blocked-image clients show nothing.  (image-alt)
  12  suggestion  Link text "click here" says nothing out of context — describe the destination instead.  (link-text)

2 problems (1 warning, 1 suggestion)

The exit code is 1 when warnings are found, so it slots into CI; suggestions alone exit 0 unless you pass --strict.

MCP Server

emailmd mcp runs the MCP server over stdio, giving a local AI client tools to render, lint, and look up docs. --partials preloads partials for every render and lint call:

emailmd mcp
emailmd mcp --partials ./partials

On this page