email

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package email sends notification batches over implicit-TLS SMTP.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig indicates invalid transport or destination settings.
	ErrInvalidConfig = errors.New("invalid email configuration")
	// ErrInvalidAddress indicates an invalid envelope address.
	ErrInvalidAddress = errors.New("invalid email address")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host          string
	Port          string
	Username      string
	Password      string
	From          string
	TLSServerName string

	// TLSConfig overrides the default TLS configuration (TLS 1.2 minimum). NewTransport clones it.
	TLSConfig *tls.Config

	// MaxIdleConnections caps SMTP connections kept open for reuse between sends,
	// avoiding a full TCP+TLS+AUTH handshake on every batch. Defaults to 4.
	MaxIdleConnections int
}

Config defines SMTP settings. All fields except TLSServerName, TLSConfig, and MaxIdleConnections are required; From does not default to Username.

type Message

type Message struct {
	Subject string
	Text    string
	HTML    string
}

Message contains rendered email content.

type Renderer

type Renderer[T any] func(batch []T) Message

Renderer renders a notification batch as email content.

type Transport

type Transport[T any] struct {
	// contains filtered or unexported fields
}

Transport is an immutable SMTP client shared safely by concurrent destinations. It keeps a small pool of authenticated connections open between sends.

func NewTransport

func NewTransport[T any](cfg Config) (*Transport[T], error)

NewTransport validates cfg and creates a Transport without network I/O.

func (*Transport[T]) Close added in v0.3.0

func (transport *Transport[T]) Close() error

Close closes every idle pooled connection and stops future pooling. Connections currently in use finish normally and are closed rather than pooled when they're returned. The Transport remains usable afterward; it just dials a fresh connection for every send from now on.

func (*Transport[T]) Recipient

func (transport *Transport[T]) Recipient(
	id string,
	address string,
	renderer Renderer[T],
) (notifier.Destination[T], error)

Recipient creates a destination for one SMTP recipient.

func (*Transport[T]) RecipientGroup

func (transport *Transport[T]) RecipientGroup(
	id string,
	addresses []string,
	renderer Renderer[T],
) (notifier.Destination[T], error)

RecipientGroup creates a destination that sends to all addresses in one SMTP transaction.

Jump to

Keyboard shortcuts

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