Documentation
¶
Index ¶
- Constants
- Variables
- func Alert(text, variant string) *hb.Tag
- func AlertStyle(backgroundColor, borderColor, textColor string) string
- func Button(text, url string) *hb.Tag
- func ButtonDanger(text, url string) *hb.Tag
- func ButtonSecondary(text, url string) *hb.Tag
- func ButtonSmall(text, url string) *hb.Tag
- func ButtonStyle(backgroundColor, borderColor, textColor string) string
- func ButtonStyleSecondary(color string) string
- func ButtonSuccess(text, url string) *hb.Tag
- func Card(children ...hb.TagInterface) *hb.Tag
- func Container(children ...hb.TagInterface) *hb.Tag
- func DefaultTemplate(options TemplateOptions) string
- func Divider() *hb.Tag
- func Heading(text string, level int) *hb.Tag
- func Paragraph(text string) *hb.Tag
- func Section(children ...hb.TagInterface) *hb.Tag
- func SetBrandColors(primary, secondary, success, danger, warning, info, light, dark string)
- func Small(text string) *hb.Tag
- func Table(headers []string, rows [][]string) *hb.Tag
- type Config
- type SMTPSender
- type SendOptions
- type Sender
- type TemplateOptions
Constants ¶
const ( // StyleHeading1 is the primary heading style (24px, bold) StyleHeading1 = "margin:0px;padding:10px 0px;text-align:left;font-size:24px;font-weight:600;color:#333333;" // StyleHeading2 is the secondary heading style (20px, bold) StyleHeading2 = "margin:0px;padding:8px 0px;text-align:left;font-size:20px;font-weight:600;color:#333333;" // StyleHeading3 is the tertiary heading style (18px, bold) StyleHeading3 = "margin:0px;padding:6px 0px;text-align:left;font-size:18px;font-weight:600;color:#333333;" // StyleParagraph is the standard paragraph style (16px, normal line height) StyleParagraph = "margin:0px;padding:10px 0px;text-align:left;font-size:16px;line-height:1.6;color:#333333;" // StyleSmall is for smaller text like disclaimers or footnotes (14px) StyleSmall = "margin:0px;padding:5px 0px;text-align:left;font-size:14px;color:#666666;" )
Typography Styles
These constants define inline CSS styles for text elements in HTML emails. Email clients require inline styles for proper rendering.
const ( // StyleContainer is a centered container with max-width (600px) StyleContainer = "max-width: 600px; margin: 0 auto; padding: 20px; background-color: #ffffff;" // StyleSection is a content section with light background StyleSection = "margin: 20px 0px; padding: 15px; background-color: #f8f9fa; border-radius: 6px;" // StyleDivider is a horizontal rule/separator StyleDivider = "height: 1px; background-color: #dee2e6; margin: 20px 0px; border: none;" // StyleCard is a bordered card container StyleCard = "padding: 20px; background-color: #ffffff; border: 1px solid #dee2e6; border-radius: 8px; margin: 10px 0px;" )
Layout Styles
These constants define inline CSS styles for layout containers and sections.
const ( // StyleAlertInfo is for informational messages (uses ColorInfo) StyleAlertInfo = "" /* 127-byte string literal not displayed */ // StyleAlertSuccess is for success messages (uses ColorSuccess) StyleAlertSuccess = "" /* 127-byte string literal not displayed */ // StyleAlertWarning is for warning messages (uses ColorWarning) StyleAlertWarning = "" /* 127-byte string literal not displayed */ // StyleAlertDanger is for error/danger messages (uses ColorDanger) StyleAlertDanger = "" /* 127-byte string literal not displayed */ )
Alert Styles
These constants define inline CSS styles for alert/notification boxes.
const ( // StyleListUnordered is for unordered (bulleted) lists StyleListUnordered = "margin: 10px 0px; padding-left: 20px; color: #333333;" // StyleListOrdered is for ordered (numbered) lists StyleListOrdered = "margin: 10px 0px; padding-left: 20px; color: #333333;" // StyleListItem is for individual list items StyleListItem = "margin: 5px 0px; line-height: 1.5;" )
List Styles
These constants define inline CSS styles for lists.
const ( // StyleTable is the base table style StyleTable = "width: 100%; border-collapse: collapse; margin: 15px 0px;" // StyleTableHead is for table header cells StyleTableHead = "background-color: #f8f9fa; border: 1px solid #dee2e6; padding: 12px; text-align: left; font-weight: 600;" // StyleTableCell is for table data cells StyleTableCell = "border: 1px solid #dee2e6; padding: 12px; text-align: left;" )
Table Styles
These constants define inline CSS styles for tables.
Variables ¶
var ( // ColorPrimary is the main brand color (default: blue) // Override example: email.ColorPrimary = "#6f42c1" // purple ColorPrimary = "#007BFF" // ColorSecondary is for secondary elements (default: gray) ColorSecondary = "#6C757D" // ColorSuccess is for positive/success states (default: green) ColorSuccess = "#28A745" // ColorDanger is for errors/danger states (default: red) ColorDanger = "#DC3545" // ColorWarning is for warnings (default: yellow/orange) ColorWarning = "#FFC107" // ColorInfo is for informational messages (default: teal/cyan) ColorInfo = "#17A2B8" // ColorLight is for light backgrounds (default: light gray) ColorLight = "#F8F9FA" // ColorDark is for dark elements (default: dark gray) ColorDark = "#343A40" )
BrandColor allows projects to customize email colors to match their brand. These variables can be overridden in a project's init() function.
var ( // StyleButtonPrimary is the main call-to-action button (uses ColorPrimary) StyleButtonPrimary = "display: inline-block; padding: 12px 24px; font-size: 16px; font-weight:600; color: white; background-color: " + ColorPrimary + "; text-align: center; text-decoration: none; border-radius: 6px; border: 1px solid " + ColorPrimary + ";" // StyleButtonSecondary is a secondary action button (outlined, uses ColorPrimary) StyleButtonSecondary = "display: inline-block; padding: 12px 24px; font-size: 16px; font-weight:600; color: " + ColorPrimary + "; background-color: transparent; text-align: center; text-decoration: none; border-radius: 6px; border: 2px solid " + ColorPrimary + ";" // StyleButtonSuccess is for positive actions (uses ColorSuccess) StyleButtonSuccess = "display: inline-block; padding: 12px 24px; font-size: 16px; font-weight:600; color: white; background-color: " + ColorSuccess + "; text-align: center; text-decoration: none; border-radius: 6px; border: 1px solid " + ColorSuccess + ";" // StyleButtonDanger is for destructive actions (uses ColorDanger) StyleButtonDanger = "display: inline-block; padding: 12px 24px; font-size: 16px; font-weight:600; color: white; background-color: " + ColorDanger + "; text-align: center; text-decoration: none; border-radius: 6px; border: 1px solid " + ColorDanger + ";" // StyleButtonSmall is a smaller button variant (uses ColorPrimary) StyleButtonSmall = "display: inline-block; padding: 8px 16px; font-size: 14px; font-weight:600; color: white; background-color: " + ColorPrimary + "; text-align: center; text-decoration: none; border-radius: 4px; border: 1px solid " + ColorPrimary + ";" )
Button Styles
These variables define inline CSS styles for button/link elements. They use BrandColor variables which can be customized per-project. Use these for call-to-action links in emails.
var ( // StyleTextCenter centers text horizontally StyleTextCenter = "text-align: center;" // StyleTextRight aligns text to the right StyleTextRight = "text-align: right;" // StyleTextMuted is for muted/secondary text (gray) StyleTextMuted = "color: #6c757d;" // StyleTextPrimary is for primary brand color text (uses ColorPrimary) StyleTextPrimary = "color: " + ColorPrimary + ";" // StyleTextSuccess is for success state text (uses ColorSuccess) StyleTextSuccess = "color: " + ColorSuccess + ";" // StyleTextDanger is for danger/error state text (uses ColorDanger) StyleTextDanger = "color: " + ColorDanger + ";" // StyleTextWarning is for warning state text (uses ColorWarning) StyleTextWarning = "color: " + ColorWarning + ";" // StyleBgLight is for light background color (uses ColorLight) StyleBgLight = "background-color: " + ColorLight + ";" // StyleBgDark is for dark background color (uses ColorDark) StyleBgDark = "background-color: " + ColorDark + ";" )
Utility Styles
These variables define inline CSS utility styles for common formatting needs. They use BrandColor variables which can be customized per-project.
Functions ¶
func AlertStyle ¶
AlertStyle generates a custom alert style with specified colors. Use this when you need alerts with custom color schemes.
Example:
customAlert := email.AlertStyle("#6f42c1", "#e9d5ff", "#3b0764")
// Creates a purple-themed alert
func ButtonDanger ¶
ButtonDanger creates a styled danger button.
func ButtonSecondary ¶
ButtonSecondary creates a styled secondary (outlined) button.
func ButtonSmall ¶
ButtonSmall creates a smaller primary button.
func ButtonStyle ¶
ButtonStyle generates a custom button style with the specified colors. Use this when you need a button with a specific brand color not covered by BrandColor variables.
Example:
customButton := email.ButtonStyle("#6f42c1", "#5a32a3", "white")
// Creates a purple button with darker purple border and white text
func ButtonStyleSecondary ¶
ButtonStyleSecondary generates a custom outlined button style. Use this for secondary actions with custom brand colors.
Example:
customSecondaryBtn := email.ButtonStyleSecondary("#6f42c1")
// Creates an outlined purple button
func ButtonSuccess ¶
ButtonSuccess creates a styled success button.
func Container ¶
func Container(children ...hb.TagInterface) *hb.Tag
Container creates a styled container with maximum width.
func DefaultTemplate ¶
func DefaultTemplate(options TemplateOptions) string
DefaultTemplate generates a standard responsive email template
func Heading ¶
Heading creates a styled heading (level 1-3). If level is outside 1-3, it defaults to Heading1.
func Section ¶
func Section(children ...hb.TagInterface) *hb.Tag
Section creates a styled section with a light background.
func SetBrandColors ¶
func SetBrandColors(primary, secondary, success, danger, warning, info, light, dark string)
SetBrandColors allows setting all brand colors at once. Call this in your project's init() function to customize email colors.
Example:
func init() {
email.SetBrandColors(
"#6f42c1", // Primary (purple)
"#6C757D", // Secondary (gray)
"#28A745", // Success (green)
"#DC3545", // Danger (red)
"#FFC107", // Warning (yellow)
"#17A2B8", // Info (teal)
"#F8F9FA", // Light
"#343A40", // Dark
)
}
Types ¶
type Config ¶
type Config struct {
// Host is the SMTP server host
Host string
// Port is the SMTP server port
Port string
// Username is the SMTP server username
Username string
// Password is the SMTP server password
Password string
// Logger for logging errors
Logger *slog.Logger
}
Config holds the email configuration
type SMTPSender ¶
type SMTPSender struct {
// contains filtered or unexported fields
}
SMTPSender implements the Sender interface using SMTP
func (*SMTPSender) Send ¶
func (s *SMTPSender) Send(options SendOptions) error
Send sends an email using SMTP
type SendOptions ¶
type SendOptions struct {
// From is the email sender
From string
// FromName is the name of the sender (unused for now)
FromName string
// To is the list of recipients
To []string
// Bcc is the list of BCC recipients
Bcc []string
// Cc is the list of CC recipients
Cc []string
// Subject is the email subject
Subject string
// HtmlBody is the HTML content of the email
HtmlBody string
// TextBody is the plain text content of the email
TextBody string
}
SendOptions defines the options for sending an email
type Sender ¶
type Sender interface {
// Send sends an email with the given options
Send(options SendOptions) error
}
Sender defines the interface for sending emails
func NewSMTPSender ¶
NewSMTPSender creates a new SMTP email sender
type TemplateOptions ¶
type TemplateOptions struct {
// Title is the email title
Title string
// Content is the HTML content to include in the template
Content string
// AppName is the application name to display in the header and footer
AppName string
// HeaderBackgroundColor is the background color for the header
HeaderBackgroundColor string
// Year is the copyright year (defaults to current year if empty)
Year string
// HeaderLinks is a map of link text to URLs for the header
HeaderLinks map[string]string
}
TemplateOptions defines the options for generating an email template