sender

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sender sends email in the background, so endpoints respond without waiting for the email provider.

Responding first keeps response times the same whether or not an email was sent, so timing can't reveal whether an account exists. Messages aren't stored anywhere: they contain live tokens, and persisting them would undo the point of storing only token hashes. The cost is that a message still being sent when the process stops is lost; Close keeps that window small on a normal shutdown.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("sender: already closed")

ErrClosed is returned by Close if it was already called.

Functions

This section is empty.

Types

type Sender

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

Sender sends messages in the background through a Mailer.

func New

func New(m mail.Mailer, log *slog.Logger) *Sender

New returns a Sender that sends through m and logs failures to log.

func (*Sender) Close

func (s *Sender) Close(ctx context.Context) error

Close stops accepting messages and waits for messages already accepted to be sent, or to fail their last retry, until ctx is done. Pending retries run immediately instead of waiting.

func (*Sender) Send

func (s *Sender) Send(msg mail.Message)

Send sends msg in the background, retrying on failure. It returns immediately. After Close, messages are dropped and logged.

func (*Sender) Wait

func (s *Sender) Wait()

Wait blocks until every message accepted so far has been sent or has failed its last retry. It's for tests; servers use Close.

Jump to

Keyboard shortcuts

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