- go-premailer pinned at v1.38.0, facts checked, MVS changes and the indirect modules tidy adds, rejected alternatives - supersedes D-10's inlining claim and lifts 35-01's default.htm gate; Branding gains a site name with the mail.from fallback - STACK.md Supporting Libraries row
7.2 KiB
7.2 KiB
Decision: finished built-in mail layouts and CSS inlining through github.com/vanng822/go-premailer
Date: 2026-11-13
Status: Accepted
Context: Phase 35 UAT gap G-35-8 (35-UAT.md, test 8, severity major), debug session .planning/debug/mail-layouts-unstyled.md, Jakub's decision of 2026-11-13 (framework only; the plugin layouts and templates follow after the framework tag), plan 35-06
What this supersedes
- D-10's inlining claim. 35-CONTEXT D-10 says the Branding colours "compile into the brand CSS slot that postcard already inlines". postcard never inlined: it placed the brand CSS and
mail.cssin the layout's style block and nothing more, so mail clients that drop style blocks showed unstyled mail. From this decision on, postcard inlines the CSS at render (below). - 35-01's "default.htm unchanged" gate. Plan 35-01 kept
modules/postcard/assets/default.htmbyte-identical (a barecontent-bodyblock). That gate is lifted: the default layout is now WinterCMS's default layout (wrapper, header with the logo or the name, white card, copyright footer), built on two new built-in partials,headerandfooter. - D-10's Branding fields. Branding gains a Site name (
site_namecolumn,postcard.Brand.SiteName). Empty, it falls back to the display name ofmail.from(AcmeforAcme <no-reply@acme.test>). Layouts get it as{{ .siteName }}, next to{{ .year }}, the current year.
Decision
github.com/vanng822/go-premailerpinned at exactly v1.38.0, packagepremailer, with its default options:RemoveClassesfalse (class attributes stay, so plugin CSS hooks and the leftover style rules still match),CssToAttributestrue (CSS widths and heights are mirrored towidth/heightattributes, as mail clients expect),KeepBangImportantfalse.- Where it runs. In postcard's render path (
renderParts), so the admin preview, the test send and real sends get the same HTML: after the layout's HTML wrapper has rendered and passedvalidateHTML, the HTML goes throughNewPremailerFromString(...).Transform(), and the result is checked byvalidateHTMLagain. The plain-text part is never touched. - What it does. It collects the rules of the document's style elements (the brand CSS, the layout's own CSS and
mail.css), applies them to the matching elements by specificity, removes the style elements, and puts the rules it cannot inline (media queries, pseudo-classes such as:hover, selectors with*) back in one style element in the head, marked!important. The DOCTYPE line is kept. - Error fallback. An inliner error (or a panic inside it, recovered) never stops mail: the un-inlined HTML is sent with its style block, and a warning keyed
inline:<layout code>is logged at most once per warn interval (D-14 spirit). - Opt-out, with WinterCMS's option name. A file layout opts out with the header key
disable_auto_inline_css(true,1oryes, any case); a database layout with the boolean columndisable_auto_inline_cssofsystem_mail_layouts(migration202611130003_mail_layout_disable_auto_inline_css), edited by a switch on the layout form's CSS tab. An opted-out layout keeps only its style block. The built-in layouts all inline. This matchesMailManager::renderTemplatein WinterCMS, which runs CssToInlineStyles unless the layout'sdisable_auto_inline_cssoption is set.
Facts checked (2026-11-13)
- Versions and dates.
go list -m -versionslists v1.38.0 as the latest tag. proxy.golang.org reports v1.38.0 published 2026-11-04T18:13:54Z (originhttps://github.com/vanng822/go-premailer, tagrefs/tags/v1.38.0, commit98a25222c9ea2827cfc13dd8f162976703574435), nine days before this decision and past the 7-day cooldown; v1.37.0 was published 2026-10-02, so releases come roughly monthly. Module sumh1:nYXopG+L6lcRV6dEAemLLE71bihun3gxgfNJZ9iYm1Q=, go.mod sumh1:6Jcm7sYO8ON3J/IIlox2fWq+YPgGopwx7VbETlZRZtY=, both verified against the checksum database bygo mod download. - Licence and maintainer. MIT (
LICENSE: Copyright (c) 2015 Nguyen Van Nhu); maintained by its author since 2015. pkg.go.dev listed 246 importing packages at planning time. - Its requirements.
github.com/PuerkitoBio/goqueryv1.13.0,github.com/inbucket/html2textv1.0.0,github.com/vanng822/cssv1.0.1,golang.org/x/netv0.62.0 (andgithub.com/stretchr/testifyfor its own tests). Its go.mod saysgo 1.26.0; this repository is at go 1.27.0. - What MVS changes here (dry run of
go getandgo mod tidyon a scratch copy of go.mod):golang.org/x/netv0.58.0 to v0.62.0,golang.org/x/cryptov0.57.0 to v0.58.0,golang.org/x/textv0.42.0 to v0.43.0,golang.org/x/termv0.46.0 to v0.47.0, and the indirectgolang.org/x/sysv0.48.0 to v0.49.0 andgolang.org/x/syncv0.23.0 to v0.24.0. - Modules
go mod tidyadds as indirect.github.com/PuerkitoBio/goqueryv1.13.0,github.com/andybalholm/cascadiav1.3.4,github.com/inbucket/html2textv1.0.0,github.com/vanng822/cssv1.0.1, and through html2text's table renderinggithub.com/olekukonko/tablewriterv1.0.7,github.com/olekukonko/errorsv1.1.0,github.com/olekukonko/llv0.0.9,github.com/fatih/colorv1.18.0,github.com/mattn/go-colorablev0.1.14,github.com/mattn/go-isattyv0.0.20 andgithub.com/ssor/bomv0.0.0-20170718123548-6386211fdfcf.github.com/gorilla/cssv1.0.1 was already in the module graph. - Fit check (the default layout with the brand CSS and a media query in
mail.css, before the go.mod change, through a scratch modfile): the DOCTYPE line was kept, class attributes were kept, the button link carriedbackground-color:#d66829in its style attribute, the media query stayed in a style element, and the output passedvalidateHTML.
Consequences
- The framework go.mod requires
github.com/vanng822/go-premailer v1.38.0; onlymodules/postcard/inline.goimports it. Every binary that links postcard links it, goquery, cascadia, html2text and tablewriter. - Follow-up for consumers. Applications and plugins that build against this checkout with a
replace(sm-demo-app, sm-user-plugin, sm-paymentgateway-plugin and others) needgo mod tidyto get the new go.sum lines; until thengo buildandgo testin them report missing go.sum entries. Their trees are not changed in 35-06; the bump comes after the framework tag. - The style block of an inlined message holds only the leftover rules, not the brand CSS and
mail.css. Tests and tools that read the style block for the brand CSS read the style attributes instead, or use a layout that opts out. - A CSS value an administrator writes is copied into style attributes.
validateHTMLruns on the inlined HTML, so ajavascript:,vbscript:ordata:address that reaches an attribute fails the render as before (and a failing override falls back to the file version, D-14).
Rejected alternatives
- An in-house inliner on
golang.org/x/net/htmlwith douceur and cascadia. No new top-level module, but postcard would own selector specificity, cascade order,!important, media-query leftovers and the attribute mirroring, with their edge cases. github.com/aymerick/douceur/inliner. Unmaintained since 2016.- No inlining. The UAT gap stays for every client that drops style blocks (several webmail clients and Outlook variants).