mail

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mail delivers team emails (magic-link logins). It exposes a small Mailer interface with two implementations: an SMTP mailer for real delivery and a log mailer for local development, which prints the message (including the magic link) to the logger so the flow can be exercised without any SMTP configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogMailer

type LogMailer struct {
	Logger *slog.Logger
}

LogMailer logs messages instead of sending them. It is the default when no SMTP host is configured, so local/dev deployments can complete the magic-link flow by reading the link from the logs.

func NewLogMailer

func NewLogMailer(logger *slog.Logger) *LogMailer

NewLogMailer creates a LogMailer.

func (*LogMailer) Send

func (m *LogMailer) Send(_ context.Context, msg Message) error

Send logs the message. The full text body (which contains the magic link) is logged at Info so an operator testing locally can copy the link.

type MagicLinkData

type MagicLinkData struct {
	// AppName is shown in the email (e.g. the team/agent name).
	AppName string
	// Link is the full verify URL the recipient clicks.
	Link string
	// TTL is how long the link remains valid.
	TTL time.Duration
}

MagicLinkData is the content for a magic-link email.

type Mailer

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

Mailer sends email messages.

type Message

type Message struct {
	To       string
	Subject  string
	TextBody string
	HTMLBody string
}

Message is an outbound email.

func MagicLinkMessage

func MagicLinkMessage(to string, d MagicLinkData) Message

MagicLinkMessage renders the login email for a recipient.

type SMTPConfig

type SMTPConfig struct {
	Host     string
	Port     int
	Username string
	Password string
	// From is the envelope/header sender address.
	From string
}

SMTPConfig configures the SMTP mailer.

type SMTPMailer

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

SMTPMailer delivers email over SMTP.

func NewSMTPMailer

func NewSMTPMailer(cfg SMTPConfig) (*SMTPMailer, error)

NewSMTPMailer creates an SMTP mailer. TLS is mandatory when a port is given (STARTTLS on 587 / implicit on 465 are handled by go-mail's port policy); auth is auto-discovered, or disabled when no username is set (common for relay-on-localhost setups).

func (*SMTPMailer) Send

func (m *SMTPMailer) Send(ctx context.Context, msg Message) error

Send delivers the message over SMTP with a plain-text body and an HTML alternative when provided.

Jump to

Keyboard shortcuts

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