email

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAccountEmail

func IsAccountEmail(templateType TemplateType) bool

IsAccountEmail returns true if the template is for account/security emails Per AI.md PART 31: Account emails go to user's account email only

func IsLocalSMTPAvailable

func IsLocalSMTPAvailable() bool

IsLocalSMTPAvailable checks if a local SMTP server is available

Types

type APITokenCreatedData

type APITokenCreatedData struct {
	*TemplateData
	Username    string
	TokenName   string
	Permissions []string
	ExpiresAt   time.Time
	CreatedAt   time.Time
	IPAddress   string
}

APITokenCreatedData holds data for API token creation notification

type AccountLockedData

type AccountLockedData struct {
	*TemplateData
	Username           string
	Reason             string
	LockedAt           time.Time
	UnlockInstructions string
}

AccountLockedData holds data for account locked notification

type AdminAlertData

type AdminAlertData struct {
	*TemplateData
	AlertType  string
	AlertLevel string
	Message    string
	Details    map[string]string
	OccurredAt time.Time
}

AdminAlertData holds data for admin alert

type AdminInviteData

type AdminInviteData struct {
	*TemplateData
	InviterName string
	InviteLink  string
	ExpiresIn   string
	Message     string
}

AdminInviteData holds data for admin invite email

type BackupCompletedData

type BackupCompletedData struct {
	*TemplateData
	BackupName string
	BackupSize string
	CreatedAt  time.Time
	FileCount  int
	Duration   string
}

BackupCompletedData holds data for backup completion notification

type BackupFailedData

type BackupFailedData struct {
	*TemplateData
	BackupName string
	Error      string
	FailedAt   time.Time
}

BackupFailedData holds data for backup failure notification Per AI.md PART 18: backup_failed template

type BreachAdminAlertData

type BreachAdminAlertData struct {
	*TemplateData
	Severity          string
	DetectedAt        time.Time
	BreachDescription string
	AffectedUsers     int
	IPAddresses       []string
	ActionRequired    string
}

BreachAdminAlertData holds data for breach alert to admins Per AI.md PART 18: breach_admin_alert template

type BreachNotificationData

type BreachNotificationData struct {
	*TemplateData
	Username           string
	BreachDate         time.Time
	BreachDescription  string
	AffectedData       []string
	RecommendedActions []string
	SupportContact     string
}

BreachNotificationData holds data for breach notification to users Per AI.md PART 18: breach_notification template

type Config

type Config struct {
	Enabled     bool // Auto-set based on SMTP availability
	SMTP        SMTPConfig
	From        FromConfig
	AdminEmails []string
}

Config holds email configuration Per AI.md PART 18: Nested SMTP and From blocks

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default email configuration Per AI.md PART 18: Sane defaults

func DetectAndConfigure

func DetectAndConfigure() *Config

DetectAndConfigure detects SMTP and returns a configured Config Per AI.md PART 18: SMTP auto-detection on first run

type DetectedSMTP

type DetectedSMTP struct {
	Host         string
	Port         int
	TLS          bool
	STARTTLS     bool
	AuthRequired bool
}

DetectedSMTP represents a detected SMTP server

func DetectSMTP

func DetectSMTP() *DetectedSMTP

DetectSMTP auto-detects SMTP servers on the local system Per AI.md PART 18: SMTP auto-detection on first run Check order: localhost, 127.0.0.1, Docker host (172.17.0.1), Gateway IP Ports: 25, 587, 465

type EmailTemplate

type EmailTemplate struct {
	// contains filtered or unexported fields
}

EmailTemplate manages email template rendering

func NewEmailTemplate

func NewEmailTemplate() *EmailTemplate

NewEmailTemplate creates a new email template manager

func (*EmailTemplate) PreviewTemplate

func (et *EmailTemplate) PreviewTemplate(templateType TemplateType, siteName, siteURL string) (subject string, body string, err error)

PreviewTemplate renders a template with sample data for preview Per AI.md PART 16: Template preview in admin panel

func (*EmailTemplate) Render

func (et *EmailTemplate) Render(templateType TemplateType, data interface{}) (subject string, body string, err error)

Render renders a template with the given data

type EmailVerificationData

type EmailVerificationData struct {
	*TemplateData
	Username         string
	Email            string
	VerificationLink string
	ExpiresIn        string
}

EmailVerificationData holds data for email verification

type FromConfig

type FromConfig struct {
	Name  string
	Email string
}

FromConfig represents the from address configuration Per AI.md PART 18: From name and email defaults

type LoginNotificationData

type LoginNotificationData struct {
	*TemplateData
	Username    string
	LoginTime   time.Time
	IPAddress   string
	UserAgent   string
	Location    string
	IsNewDevice bool
}

LoginNotificationData holds data for login notification

type MFAReminderData

type MFAReminderData struct {
	*TemplateData
	Username    string
	SetupLink   string
	DismissLink string
}

MFAReminderData holds data for MFA reminder email Per AI.md PART 18: Gentle prompt to enable MFA

type Mailer

type Mailer struct {
	// contains filtered or unexported fields
}

Mailer handles email sending

func NewMailer

func NewMailer(cfg *Config) *Mailer

NewMailer creates a new mailer

func (*Mailer) IsEnabled

func (ml *Mailer) IsEnabled() bool

IsEnabled returns whether email is enabled

func (*Mailer) Send

func (ml *Mailer) Send(msg *Message) error

Send sends an email message

func (*Mailer) SendAlert

func (ml *Mailer) SendAlert(alertType, message string) error

SendAlert sends an alert email to admins

func (*Mailer) SendSecurityAlert

func (ml *Mailer) SendSecurityAlert(event, ip, details string) error

SendSecurityAlert sends a security alert email

func (*Mailer) SendToAdmins

func (ml *Mailer) SendToAdmins(subject, body string) error

SendToAdmins sends an email to all configured admin addresses

func (*Mailer) TestConnection

func (ml *Mailer) TestConnection() error

TestConnection tests the SMTP connection Per AI.md PART 18: Connection test on startup

type MaintenanceNoticeData

type MaintenanceNoticeData struct {
	*TemplateData
	ScheduledAt      time.Time
	Duration         string
	Reason           string
	AffectedServices []string
}

MaintenanceNoticeData holds data for maintenance notice email

type Message

type Message struct {
	To          []string
	CC          []string
	BCC         []string
	Subject     string
	Body        string
	HTMLBody    string
	ContentType string
	Headers     map[string]string
}

Message represents an email message

func NewMessage

func NewMessage(to []string, subject, body string) *Message

NewMessage creates a new email message

func (*Message) SetHTML

func (m *Message) SetHTML(html string)

SetHTML sets the HTML body

type PasswordChangedData

type PasswordChangedData struct {
	*TemplateData
	Username  string
	ChangedAt time.Time
	IPAddress string
	UserAgent string
}

PasswordChangedData holds data for password changed notification

type PasswordResetData

type PasswordResetData struct {
	*TemplateData
	Username    string
	ResetLink   string
	ExpiresIn   string
	IPAddress   string
	RequestedAt time.Time
}

PasswordResetData holds data for password reset email

type SMTPConfig

type SMTPConfig struct {
	Host     string
	Port     int
	Username string
	Password string
	TLS      string // auto, starttls, tls, none
}

SMTPConfig represents SMTP server configuration Per AI.md PART 18: SMTP configuration

type SSLExpiringData

type SSLExpiringData struct {
	*TemplateData
	Domain    string
	ExpiresAt time.Time
	DaysLeft  int
	RenewLink string
}

SSLExpiringData holds data for SSL expiration warning Per AI.md PART 18: ssl_expiring template

type SSLRenewedData

type SSLRenewedData struct {
	*TemplateData
	Domain     string
	RenewedAt  time.Time
	ValidUntil time.Time
}

SSLRenewedData holds data for SSL renewal confirmation Per AI.md PART 18: ssl_renewed template

type SchedulerErrorData

type SchedulerErrorData struct {
	*TemplateData
	TaskName    string
	Error       string
	FailedAt    time.Time
	TaskDetails map[string]string
}

SchedulerErrorData holds data for scheduler error notification Per AI.md PART 18: scheduler_error template

type SecurityAlertData

type SecurityAlertData struct {
	*TemplateData
	Event          string
	Severity       string
	IPAddress      string
	Details        string
	OccurredAt     time.Time
	ActionRequired string
}

SecurityAlertData holds data for security alert

type TemplateData

type TemplateData struct {
	SiteName     string
	SiteURL      string
	Year         int
	SupportEmail string
}

TemplateData holds common template data

func NewTemplateData

func NewTemplateData(siteName, siteURL, supportEmail string) *TemplateData

NewTemplateData creates template data with defaults

type TemplateInfo

type TemplateInfo struct {
	Type           TemplateType `json:"type"`
	Name           string       `json:"name"`
	Description    string       `json:"description"`
	IsAccountEmail bool         `json:"is_account_email"`
}

TemplateInfo contains metadata about an email template Per AI.md PART 31: Account emails vs Notification emails

func GetAllTemplateTypes

func GetAllTemplateTypes() []TemplateInfo

GetAllTemplateTypes returns a list of all available email template types Per AI.md PART 16: Admin should be able to preview email templates Per AI.md PART 31: Templates are marked as account (security) or notification

type TemplateType

type TemplateType string

TemplateType represents an email template type

const (
	TemplateWelcome           TemplateType = "welcome"
	TemplatePasswordReset     TemplateType = "password_reset"
	TemplatePasswordChanged   TemplateType = "password_changed"
	TemplateLoginNotification TemplateType = "login_notification"
	TemplateEmailVerification TemplateType = "email_verification"
	TemplateAccountLocked     TemplateType = "account_locked"
	TemplateAdminAlert        TemplateType = "admin_alert"
	TemplateWeeklyReport      TemplateType = "weekly_report"
	TemplateSecurityAlert     TemplateType = "security_alert"
	TemplateAPITokenCreated   TemplateType = "api_token_created"
	// Additional templates per AI.md PART 16
	TemplateAdminInvite       TemplateType = "admin_invite"
	Template2FAEnabled        TemplateType = "two_factor_enabled"
	Template2FADisabled       TemplateType = "two_factor_disabled"
	TemplateBackupCompleted   TemplateType = "backup_completed"
	TemplateUpdateAvailable   TemplateType = "update_available"
	TemplateMaintenanceNotice TemplateType = "maintenance_notice"
	// Additional templates per AI.md PART 18
	TemplateMFAReminder        TemplateType = "mfa_reminder"
	TemplateBackupFailed       TemplateType = "backup_failed"
	TemplateSSLExpiring        TemplateType = "ssl_expiring"
	TemplateSSLRenewed         TemplateType = "ssl_renewed"
	TemplateSchedulerError     TemplateType = "scheduler_error"
	TemplateBreachNotification TemplateType = "breach_notification"
	TemplateBreachAdminAlert   TemplateType = "breach_admin_alert"
	TemplateTest               TemplateType = "test"
)

type TestEmailData

type TestEmailData struct {
	*TemplateData
	SentAt time.Time
}

TestEmailData holds data for test email Per AI.md PART 18: test template

type TwoFactorDisabledData

type TwoFactorDisabledData struct {
	*TemplateData
	Username   string
	DisabledAt time.Time
	IPAddress  string
	Reason     string
}

TwoFactorDisabledData holds data for 2FA disabled notification

type TwoFactorEnabledData

type TwoFactorEnabledData struct {
	*TemplateData
	Username  string
	EnabledAt time.Time
	IPAddress string
	Method    string
}

TwoFactorEnabledData holds data for 2FA enabled notification

type UpdateAvailableData

type UpdateAvailableData struct {
	*TemplateData
	CurrentVersion string
	NewVersion     string
	ReleaseDate    time.Time
	ReleaseNotes   string
	UpdateURL      string
}

UpdateAvailableData holds data for update available notification

type WeeklyReportData

type WeeklyReportData struct {
	*TemplateData
	PeriodStart   time.Time
	PeriodEnd     time.Time
	TotalSearches int
	UniqueUsers   int
	TopQueries    []string
	EngineStats   map[string]int
	ErrorCount    int
}

WeeklyReportData holds data for weekly report

type WelcomeData

type WelcomeData struct {
	*TemplateData
	Username string
	Email    string
}

WelcomeData holds data for welcome email

Jump to

Keyboard shortcuts

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