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
- func EventKeys() []string
- func ForceScheme(page, scheme string) string
- func GlobalValues(b Branding, now time.Time) map[string]string
- func SampleValues() map[string]string
- func SubstituteText(text string, values map[string]string) string
- func ValidateBranding(b EmailBranding, lim BrandingLimits) error
- func ValidateHTTPSURL(raw string, maxLen int) error
- func ValidateLayout(l Layout) error
- func ValidateTemplate(e Event, t Template) error
- func ValidateTokens(text string, allowed []string) error
- type Branding
- type BrandingLimits
- type EmailBranding
- type Event
- type FooterLink
- type Layout
- type Options
- type Rendered
- type Template
- type Token
Constants ¶
const ( EnvMaxLogoURL = "APP_EMAIL_BRANDING_MAX_LOGO_URL" EnvMaxLinkLabel = "APP_EMAIL_BRANDING_MAX_LINK_LABEL" )
Env names for the branding caps; each falls back to the default below when unset or invalid.
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.
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.
const ( ScopeGlobal = "global" ScopeRecipient = "recipient" ScopeEvent = "event" )
Token scopes.
Variables ¶
This section is empty.
Functions ¶
func ForceScheme ¶
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 ¶
GlobalValues returns the global-scope token values for b.
func SampleValues ¶
SampleValues returns every token's sample value, for previews.
func SubstituteText ¶
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 ValidateBranding ¶
func ValidateBranding(b EmailBranding, lim BrandingLimits) error
ValidateBranding refuses anything unsafe or oversized; it is the single save-time gate.
func ValidateHTTPSURL ¶
ValidateHTTPSURL accepts an empty string or an https URL with a host, no credentials and no whitespace or control characters. The server never fetches it; it only lands in an href or img src.
func ValidateLayout ¶
ValidateLayout checks the header image is an https URL and the footer only uses global tokens.
func ValidateTemplate ¶
ValidateTemplate checks the subject, preheader and body against the tokens e supports.
func ValidateTokens ¶
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 BrandingLimits ¶
BrandingLimits caps the size of each branding field.
func LimitsFromEnv ¶
func LimitsFromEnv() BrandingLimits
LimitsFromEnv reads the branding caps from the environment.
type EmailBranding ¶
type EmailBranding struct {
LogoURL string `json:"logo_url"`
BrandColor string `json:"brand_color"`
ShowPoweredBy bool `json:"show_powered_by"`
}
EmailBranding is what an operator controls about how every rich email looks. The footer is structured text plus allowlisted links: there is deliberately no raw HTML field.
func (EmailBranding) Layout ¶
func (b EmailBranding) Layout() Layout
Layout turns validated branding into the layout the renderer wears.
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.
type FooterLink ¶
type FooterLink struct {
}
FooterLink is one labelled https link in the email footer.
type Layout ¶
type Layout struct {
HeaderImageURL string `json:"header_image_url"`
ShowPoweredBy bool `json:"show_powered_by,omitempty"`
}
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.
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.