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.mdTo install it as a global command:
npm install -g emailmdUsage
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
| Option | Description |
|---|---|
-o, --output <f> | Write output to a file instead of stdout |
-t, --text | Output plain text instead of HTML |
-m, --minify | Minify the HTML output |
-b, --beautify | Pretty-print the HTML output (ignored with -m) |
--escape-html | Escape 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. |
--strict | lint only: exit non-zero on suggestions as well |
-h, --help | Show help |
-v, --version | Show version number |
Examples
Render a markdown file to HTML:
emailmd input.mdWrite the output to a file:
emailmd input.md -o output.htmlGet the plain text version (for the text/plain MIME part):
emailmd input.md --textMinify the HTML output (useful for staying under Gmail's 102KB clip limit):
emailmd input.md --minify -o output.htmlPretty-print the HTML output (handy for reading it straight in the terminal):
emailmd input.md --beautifyEscape 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.htmlLoad 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.mdPipe from another command:
echo "# Hello" | emailmd
curl -s https://example.com/template.md | emailmd -o email.htmlLinting
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