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 ValidateLayout(l Layout) error
- func ValidateTemplate(e Event, t Template) error
- func ValidateTokens(text string, allowed []string) error
- type Branding
- type Event
- type Layout
- type Options
- type Rendered
- type Template
- type Token
Constants ¶
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" 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 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 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 Layout ¶
type Layout struct {
HeaderImageURL string `json:"header_image_url"`
}
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.