mailtemplates

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mailtemplates renders the platform's emails: a token registry, a {{token}} substitution engine with no code execution, a small safe markup and one shared branded layout around every event template.

Index

Constants

View Source
const (
	CategorySystem       = "system"
	CategoryAnnouncement = "announcement"
)

Event categories. System mail is security or account related and ignores the opt-out list; announcements honor it and carry an unsubscribe link.

View Source
const (
	EventPasswordReset      = "password_reset"
	EventUserInvite         = "user_invite"
	EventLoginCode          = "login_code"
	EventSignInAlert        = "signin_alert"
	EventEmailChanged       = "email_changed"
	EventEmailChangeConfirm = "email_change_confirm"
	EventAlertNotification  = "alert_notification"
	EventCertExpiry         = "cert_expiry_alert"
	EventCertExpiryPlain    = "cert_expiry_alert_plain"
	EventDeployNotification = "deploy_notification"
	EventDeployApproval     = "deploy_approval"
	EventTestEmail          = "test_email"
	EventAnnouncement       = "announcement"
	EventMaintenanceNotice  = "maintenance_notice"
)

Event keys.

View Source
const (
	ScopeGlobal    = "global"
	ScopeRecipient = "recipient"
	ScopeEvent     = "event"
)

Token scopes.

Variables

This section is empty.

Functions

func EventKeys

func EventKeys() []string

EventKeys returns the sorted event keys.

func ForceScheme

func ForceScheme(page, scheme string) string

ForceScheme pins a rendered page to "light" or "dark" for previews; any other value leaves the page following the viewer's own setting.

func GlobalValues

func GlobalValues(b Branding, now time.Time) map[string]string

GlobalValues returns the global-scope token values for b.

func SampleValues

func SampleValues() map[string]string

SampleValues returns every token's sample value, for previews.

func SubstituteText

func SubstituteText(text string, values map[string]string) string

SubstituteText fills tokens for a plain-text field such as a subject. Line breaks in values are flattened so a value cannot extend a header.

func ValidateLayout

func ValidateLayout(l Layout) error

ValidateLayout checks the header image is an https URL and the footer only uses global tokens.

func ValidateTemplate

func ValidateTemplate(e Event, t Template) error

ValidateTemplate checks the subject, preheader and body against the tokens e supports.

func ValidateTokens

func ValidateTokens(text string, allowed []string) error

ValidateTokens reports every token in text that is malformed or not in allowed. Saving a template with any of these is refused.

Types

type Branding

type Branding struct {
	Name             string
	PrimaryColor     string
	PrimaryColorDark string
	SupportEmail     string
	DashboardURL     string
	InstanceName     string
}

Branding is the identity the layout wears, filled from the brand layer.

type Event

type Event struct {
	Key         string   `json:"key"`
	Label       string   `json:"label"`
	Description string   `json:"description"`
	Category    string   `json:"category"`
	Tokens      []string `json:"tokens"`
	Default     Template `json:"default"`
}

Event is one kind of email the platform sends.

func Events

func Events() []Event

Events returns every event definition, in a stable order.

func LookupEvent

func LookupEvent(key string) (Event, bool)

LookupEvent finds an event by key.

type Layout

type Layout struct {
	HeaderImageURL string `json:"header_image_url"`
	FooterText     string `json:"footer_text"`
}

Layout is the operator-editable frame around every event template.

type Options

type Options struct {
	// UnsubscribeURL, when set, adds the unsubscribe line to the footer.
	UnsubscribeURL string
}

Options carries per-message values the layout needs.

type Rendered

type Rendered struct {
	Subject   string `json:"subject"`
	Preheader string `json:"preheader"`
	Text      string `json:"text"`
	HTML      string `json:"html"`
}

Rendered is a finished message.

func Render

func Render(b Branding, l Layout, t Template, values map[string]string, o Options) Rendered

Render produces the subject, plain text and HTML for t inside the shared layout. Values are escaped for HTML, so a value can never add markup.

type Template

type Template struct {
	Subject   string `json:"subject"`
	Preheader string `json:"preheader"`
	Body      string `json:"body"`
}

Template is the editable part of an email.

type Token

type Token struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Sample      string `json:"sample"`
	Scope       string `json:"scope"`
}

Token is one substitutable value.

func LookupToken

func LookupToken(name string) (Token, bool)

LookupToken finds a token by name.

func Tokens

func Tokens() []Token

Tokens returns every registered token, sorted by scope then name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL