mail

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package mail sends email: an SMTP driver, a log driver for development, MIME building and the localized templates. Sending normally happens in a background job (internal/jobs); the account service enqueues the rendered Message.

Index

Constants

View Source
const (
	DriverNone = "none"
	DriverSMTP = "smtp"
	DriverLog  = "log" // prints mail to the server log instead of sending (development)
)

Drivers.

View Source
const (
	KindVerifyEmail   = "verify_email"
	KindResetPassword = "reset_password"
	KindEmailChanged  = "email_changed"
	KindTest          = "test"
)

Kinds of mail SkinLoom sends.

Variables

View Source
var ErrDisabled = errors.New("mail is not configured")

ErrDisabled means no mail driver is configured.

Functions

func HasTemplate added in v1.1.0

func HasTemplate(kind string) bool

HasTemplate reports whether kind names a built-in email template.

func SettingDefs

func SettingDefs() []settings.Def

SettingDefs are the mail settings.

Types

type Config

type Config struct {
	Driver     string
	From       string // "Name <address>" or a bare address
	Host       string
	Port       int
	Username   string
	Password   string
	Encryption string // tls (implicit, usually port 465) | starttls (usually 587) | none
}

Config is the active mail setup (from settings).

func ConfigFrom

func ConfigFrom(s *settings.Snapshot) Config

ConfigFrom reads the mail setup from a settings snapshot.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether mail can be sent.

type Data

type Data struct {
	Site     string // localized site name
	Nickname string
	Link     string
	NewEmail string // email_changed
}

Data fills a template.

type Mailer

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

Mailer sends messages with the configured driver.

func New

func New(log *slog.Logger) *Mailer

New creates a Mailer.

func (*Mailer) Send

func (s *Mailer) Send(ctx context.Context, c Config, m Message) error

Send delivers m. SMTP errors are returned as is: callers log them or show them to administrators, never to visitors.

type Message

type Message struct {
	To      string `json:"to"`
	Subject string `json:"subject"`
	Text    string `json:"text"`
	HTML    string `json:"html"`
}

Message is one email, already rendered.

func Render

func Render(kind, locale, to string, d Data) Message

Render builds a message for kind in locale (falling back to zh-CN).

Jump to

Keyboard shortcuts

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