mailer

package
v0.0.0-...-610d9af Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: GPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mailer sends the transactional emails of the auth flows (verify your email, reset your password). The service package declares the one-method interface it needs; this package holds implementations.

Console writes the message to the application log, which is all you need to develop and demo the flows: copy the link from the log. In production, implement the same method on top of an email API or SMTP (SES, Postmark, Resend, ...), ideally behind a queue, so a slow provider does not slow down requests and failures can be retried.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Console

type Console struct {
	Log *slog.Logger
}

Console logs every message instead of sending it. THIS DELIBERATELY LOGS THE LINK, WHICH CONTAINS A LIVE TOKEN: it is a development tool. Never use it where logs are shared or retained.

func (Console) Send

func (c Console) Send(ctx context.Context, to, subject, body string) error

Send implements the service.Mailer interface.

type Memory

type Memory struct {

	// Err, when set, is returned by Send (and nothing is recorded), to test mail failures.
	Err error
	// contains filtered or unexported fields
}

Memory records messages instead of sending them. It is the test double: a test performs an action ("forgot password"), then reads the token out of the captured email, exactly like a user would click the link. Safe for concurrent use.

func (*Memory) Last

func (m *Memory) Last() (Message, bool)

Last returns the most recent message and whether there is one.

func (*Memory) Send

func (m *Memory) Send(_ context.Context, to, subject, body string) error

Send implements the service.Mailer interface.

func (*Memory) Sent

func (m *Memory) Sent() []Message

Sent returns a copy of everything sent so far.

type Message

type Message struct {
	To, Subject, Body string
}

Message is one captured email.

Jump to

Keyboard shortcuts

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