mailer

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0, MIT Imports: 21 Imported by: 0

Documentation

Overview

Package mailer renders templates and sends transactional email over SMTP.

Index

Constants

View Source
const DefaultSendTimeout = 15 * time.Second

DefaultSendTimeout bounds one SMTP transaction.

Variables

This section is empty.

Functions

func SettingsFromValues

func SettingsFromValues(values map[string]string, fallback config.MailerConfig) config.MailerConfig

SettingsFromValues merges app settings over the fallback config.

Types

type Mailer

type Mailer interface {
	Send(ctx context.Context, msg Message) error
}

Mailer renders and delivers transactional email.

func New

func New(cfg config.MailerConfig, opts Options) Mailer

New builds a mailer from SMTP settings. Every compiled template is parsed eagerly so a broken template fails the boot, not the first send.

type Message

type Message struct {
	// To is the recipient address.
	To string

	// Subject is the message subject.
	Subject string

	// Template names resolve to matching HTML and text templates.
	Template string

	// Data feeds the template's .Data tree.
	Data map[string]any
}

Message is a message to render and send.

type Options

type Options struct {
	// Templates is the source of template files.
	Templates fs.FS

	// LogoURL is available to templates.
	LogoURL string

	// Logger receives send attempts and failures. Nil disables logging.
	Logger logger.Logger

	// SendTimeout bounds one SMTP transaction when ctx has no
	// deadline. Zero uses DefaultSendTimeout.
	SendTimeout time.Duration
}

Options configures New.

type SettingsSource

type SettingsSource func(ctx context.Context) (config.MailerConfig, error)

SettingsSource resolves SMTP settings for one send.

type SettingsSourceSetter

type SettingsSourceSetter interface {
	SetSettingsSource(source SettingsSource)
}

SettingsSourceSetter is implemented by mailers that accept a settings source.

Jump to

Keyboard shortcuts

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