Getting started

Introduction

What lttr is, the three things that make a message, and what is checked at each stage.

lttr is a Go engine for email templates. Authors write each email as Markdown with components (Comark): ::statement, ::receipt, :button and the rest, depending on which kit the template uses. You give the template a Go data type. lttr.Compile checks the template against that type once, at startup, and Render fills in the data and returns a *lttr.Message with Outlook-safe HTML, a plain-text part and an envelope, ready to send as MIME.

The engine holds no design of its own. Colours, fonts, layout, the components a template may use, even the closing "Thanks," come from a kit, a directory of templates and YAML that you own. lttr ships two: Plain, a small neutral starter lttr kit init copies as your base, and Quiet, a complete editorial kit with 24 components, worked through nine reference emails for Loam, a fictional farm-to-door marketplace.

See the three layers

main.go
var welcome = lttr.MustCompile[Welcome](myKit, "welcome", src)

msg, err := welcome.Render(renderer, recipient, Welcome{FirstName: "Ada"})

Three things meet in these two lines:

  • The template is Markdown with YAML frontmatter. The frontmatter names the template and the profile it sends under, and holds the subject and preheader. The body is a stack of the kit's components, and loose Markdown goes into the kit's default component. Merge tags ({{workspace}}) and bindings (:order="order") refer to fields of your data type.
  • The kit is an fs.FS of design tokens, a document layout, the HTML for Markdown blocks, and the components the template may use, each with a schema. myKit above is whatever kit.Load returned, or a shipped kit's MustKit().
  • The message is what Render returns: Outlook-safe HTML, a plain-text part rendered from the same laid-out document (not scraped from the HTML), and the envelope (subject, profile, recipient). Render either returns a complete *Message or an error, never a partial one.

Know what is checked, and when

Three stages, each catching what it can before the next one runs:

StageFunctionCatches
Kit loadkit.Load (or a shipped kit's MustKit())Every kit template statically checked against the view it executes with: field and method chains on bound Go types, attribute names against the schema, token and var names. A typo fails once, at the kit's own file position, for every template that will ever use it.
Template compilelttr.Compile / MustCompileThe Comark source, the frontmatter, every component against its kit schema, and every merge tag and binding against your Go type. Errors are *ir.Error values carrying name:line:col, returned all at once. An unknown name gets the closest known one as a suggestion: (did you mean workspace?).
RenderTemplate.RenderWhatever depends on the data: a merge tag with no value and no fallback, an invalid URL, an empty subject, a profile that needs an unsubscribe URL the recipient lacks. Non-fatal findings (HTML over 90 KB) land in Message.Warnings instead.

MustCompile belongs in a package-level var, so a broken template panics when your service starts, not when the first email goes out.

Know who this is for

lttr fits a Go service that sends its own transactional, marketing or internal email and wants the compiler, not a runtime surprise, to catch a broken template. You keep the design (a kit you write once, or Plain as a starting point) and the sending policy (which profile, which SMTP relay, which suppression list); lttr keeps the checks and the markup honest. It sends over SMTP or hands you raw MIME bytes; provider SDKs, web fonts and a visual editor are out of scope.

Go further

Installation

Add the module and the CLI.

Quick start

One file: a type, a template, a profile, a render.

Comark syntax

Components, spans, attributes and merge tags.

What is a kit

File layout, kit.Load, and the two shipped kits.

Profiles and config

Senders, headers and the renderer's config.

Agent skill

Teach your coding agent to write lttr templates and kits.
Copyright © 2026