mail

package
v0.0.0-...-6451a0a Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package mail sends plain-text email. Every service that mails a person goes through Sender, so tests swap in a Recorder and development without a mail server swaps in a Logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Host is the SMTP server. Empty sends nothing and logs each message instead.
	Host     string
	Port     int
	Username string
	Password string
	From     string
}

func Load

func Load() Config

func (Config) Validate

func (c Config) Validate() error

type Logger

type Logger struct {
	Logger *slog.Logger
}

Logger writes each message to the log instead of sending it, for development without a mail server. The body holds live links, so it must never be used where logs are shared.

func (Logger) Send

func (l Logger) Send(ctx context.Context, message Message) error

type Message

type Message struct {
	To      string
	Subject string
	Text    string
}

type Recorder

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

Recorder keeps every message for a test to read back.

func (*Recorder) Last

func (r *Recorder) Last(address string) (Message, bool)

Last returns the latest message sent to address, and false when there is none.

func (*Recorder) Messages

func (r *Recorder) Messages() []Message

func (*Recorder) Send

func (r *Recorder) Send(_ context.Context, message Message) error

type SMTP

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

func (*SMTP) Send

func (s *SMTP) Send(ctx context.Context, message Message) error

Send upgrades to TLS whenever the server offers STARTTLS. net/smtp refuses to send credentials over a plain connection to anything but localhost, so a server without STARTTLS gets none.

type Sender

type Sender interface {
	Send(ctx context.Context, message Message) error
}

func New

func New(cfg Config, logger *slog.Logger) Sender

New returns the SMTP sender, or a Logger when no host is configured.

Jump to

Keyboard shortcuts

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