systemmail

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package systemmail sends ReputeCast's own mail (password resets, email changes, team invitations, notifications, double opt-in confirmations, test messages) through the workspace's System-stream route, whose fallback takes over when the provider is down or refuses the message. It implements mailer.Sender (App.Mail).

Messages without a workspace (a password reset, an email change) go through the recipient's first workspace, by membership date, that has a usable System route, and otherwise through the instance's oldest workspace with one. The From address is the workspace's System sender, else its default sender, else its first sender.

Index

Constants

This section is empty.

Variables

View Source
var ErrDemoProvider = errors.New("this is a sample provider from the demo data and can't send real mail; connect a sending provider and route the System stream to it")

ErrDemoProvider is returned outside development for the demo's sample providers: they have no real account behind them.

View Source
var ErrNoSender error = noSenderError{}

ErrNoSender means the workspace has no sender identity to send from. It counts as mailer.ErrNoSystemProvider, so callers fall back the way they do without a System provider (copy a link, the CLI command).

Functions

func HTMLToText

func HTMLToText(h string) string

HTMLToText is a rough plain-text version of an HTML fragment: links keep their URL, paragraphs become lines.

func TextToHTML

func TextToHTML(text, linkColor string) string

TextToHTML turns plain text into paragraphs with clickable links in the brand's colour.

Types

type Brand

type Brand struct {
	Name   string
	Accent string // hex colour of the brand mark
	Footer string // "Sent by Acme ReputeCast · reputecast.acme.io"
}

Brand is who a system message comes from: ReputeCast (the instance) for messages to team members, the publisher for messages to subscribers.

type Deliverer

type Deliverer struct {
	Pool    *pgxpool.Pool
	Q       *store.Queries
	Factory *manage.Factory
	// ApplyEvent records a normalized event through the ingest pipeline
	// (message status, provider stats, event log).
	ApplyEvent func(ctx context.Context, tx pgx.Tx, p store.Provider, ev providers.Event) error
	// DevSMTP is the development mail catcher ("localhost:1025"); empty
	// outside development.
	DevSMTP string
	Log     *slog.Logger
	Now     func() time.Time
}

Deliverer sends one message through a connected provider and records it like any other send: a messages row (stream system, with its kind), the provider's call statistics and, when the provider reports no delivery events of its own (SMTP), the delivered event inferred from its 250 reply.

Demo providers (providers.config "demo": true) never reach a provider API: in development their mail goes to DevSMTP (Mailpit) and is recorded as delivered by that provider; elsewhere Send refuses with ErrDemoProvider.

func (*Deliverer) Send

func (d *Deliverer) Send(ctx context.Context, p store.Provider, msg providers.Message, kind string) (Delivery, error)

Send delivers msg through p and records it. kind tags the message ("password_reset", "invite", "test").

func (*Deliverer) Usable

func (d *Deliverer) Usable(p store.Provider) bool

Usable reports whether Send can deliver through p at all (demo providers only in development).

type Delivery

type Delivery struct {
	ProviderMessageID string
	QueuedAt          time.Time
	SentAt            time.Time
	// Via names where a demo provider's mail went ("Mailpit").
	Via string
}

Delivery is the outcome of one message.

type Mailer

type Mailer struct {
	Q       *store.Queries
	Deliver *Deliverer
	// Instance returns the instance name and public URL for the brand.
	Instance func(ctx context.Context) (name, publicURL string)
	Log      *slog.Logger
	Now      func() time.Time
	// contains filtered or unexported fields
}

Mailer is the System-stream mailer.

func (*Mailer) Forget

func (m *Mailer) Forget()

Forget drops the cached availability (after routing or providers changed).

func (*Mailer) SendSystem

func (m *Mailer) SendSystem(ctx context.Context, msg mailer.Message) (string, error)

SendSystem implements mailer.Sender: it returns the name of the provider that accepted the message.

func (*Mailer) SystemAvailable

func (m *Mailer) SystemAvailable(ctx context.Context, workspaceID *uuid.UUID) bool

SystemAvailable implements mailer.Sender. It answers from a 30-second cache, so screens can ask on every load.

type Rendered

type Rendered struct {
	HTML string
	Text string
}

Rendered is a message ready for a provider.

func Render

func Render(kind string, brand Brand, subject, text, body string) (Rendered, error)

Render wraps a message's body in the branded layout of its kind: the brand mark and name, the body, and a footer that says why it was sent. Callers pass their own HTML fragment (trusted: they escape their values); messages with text only get it converted.

func RenderIn

func RenderIn(l i18n.Lang, kind string, brand Brand, subject, text, body string) (Rendered, error)

RenderIn is Render with the layout in the reader's language.

Jump to

Keyboard shortcuts

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