mail

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mail delivers moth's transactional emails. Two transports: SMTP for production and a console logger so the whole auth flow works in dev with zero setup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brand

type Brand struct {
	// Name of the project (or "moth" for instance-level mail).
	Name string
	// LogoURL is the absolute URL of the project's light-scheme logo;
	// empty renders no logo. Email clients overwhelmingly render on white,
	// so the light variant is the right one.
	LogoURL string
	// Accent is the button background (#RRGGBB); theme primary color.
	Accent string
	// OnAccent is the button text color (#RRGGBB); theme onPrimary.
	OnAccent string
}

Brand is the sender identity an email renders with: the project name plus the optional design-system accents (plan/06). The zero-value accents fall back to moth's neutral defaults, so a Brand{Name: ...} alone always produces a decent email.

type Console

type Console struct {
	Log *slog.Logger
}

Console logs the full email instead of sending it — the dev default.

func (Console) Send

func (c Console) Send(_ context.Context, m Message) error

type Content

type Content struct {
	Subject     string
	Paragraphs  []string
	ButtonLabel string
	ButtonURL   string
}

Content is a pre-localized transactional email: the subject, body paragraphs and an optional action button, already resolved from the i18n catalog for the recipient's negotiated locale by the caller. It lets the auth handlers ship localized copy through the same branded layout the English helpers above use.

type Dynamic

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

Dynamic is a Mailer whose underlying transport can be swapped at runtime, so the admin console can reconfigure SMTP without a restart.

func NewDynamic

func NewDynamic(m Mailer) *Dynamic

NewDynamic wraps m in a swappable mailer.

func (*Dynamic) Send

func (d *Dynamic) Send(ctx context.Context, m Message) error

func (*Dynamic) Set

func (d *Dynamic) Set(m Mailer)

Set replaces the transport used by subsequent Sends.

type Mailer

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

Mailer sends transactional emails.

type Message

type Message struct {
	To      string
	Subject string
	Text    string
	HTML    string
}

Message is one email ready to send.

func AccountExists

func AccountExists(brand Brand, to string) Message

AccountExists is sent instead of an error when an enumeration-safe project sees a signup with an already-registered email.

func AdminInvite

func AdminInvite(to, link string) Message

AdminInvite is the operator-invitation email for the moth admin console.

func EmailChangeConfirm

func EmailChangeConfirm(brand Brand, to, link string) Message

EmailChangeConfirm goes to the NEW address to prove ownership before the account email switches.

func EmailChangedNotice

func EmailChangedNotice(brand Brand, to, newEmail, revertLink string) Message

EmailChangedNotice goes to the OLD address after the switch, carrying a revert link.

func PasswordReset

func PasswordReset(brand Brand, to, link string) Message

PasswordReset is the "reset your password" email.

func RenderContent

func RenderContent(brand Brand, to string, c Content) Message

RenderContent builds a branded email from pre-resolved localized content.

func Test

func Test(to string) Message

Test is the probe email sent by the admin console's "send test email" button.

func UserInvite

func UserInvite(brand Brand, to, link string) Message

UserInvite is the "set your password" email for an account created by an operator in the admin console.

func Verification

func Verification(brand Brand, to, link string) Message

Verification is the "confirm your email address" email.

type SMTP

type SMTP struct {
	Host     string
	Port     int
	Username string
	Password string
	From     string
}

SMTP sends through a configured SMTP relay, with STARTTLS when the server offers it and PLAIN auth when a username is configured.

func (SMTP) Send

func (s SMTP) Send(_ context.Context, m Message) error

Jump to

Keyboard shortcuts

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