email

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: BSD-3-Clause Imports: 9 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 email delivers user-facing notifications over SMTP.

Two scenarios drive a send today (see the API hook points in internal/server) :

  • a user is @-mentioned in a chat / comment payload
  • a new comment lands on a project the recipient shares

The package itself is intentionally hook-agnostic — it just exposes a Sender contract that the API layer calls with the already-resolved recipient list + rendered body. Mention parsing, project membership lookup and idempotency live in the call sites.

Runtime configuration is environment-only and read once at startup (see internal/server/api_settings_email.go for the read-only admin summary endpoint). Swapping SMTP creds requires a restart ; that's a deliberate constraint — there is no hot-reload code path and no plan for one. Operators set :

WEFT_LOOM_SMTP_HOST   e.g. smtp.example.org
WEFT_LOOM_SMTP_PORT   default 587
WEFT_LOOM_SMTP_USER   PLAIN auth username (typically the From)
WEFT_LOOM_SMTP_PASS   PLAIN auth password
WEFT_LOOM_SMTP_FROM   envelope + From: header

When SMTPHost is empty NewSender returns a NoopSender that logs the intended delivery to the configured slog logger and returns nil ; this keeps the call sites free of "if mailer != nil" branches and makes "what would have been sent" easy to read in dev.

Pure-Go : the SMTP path uses net/smtp from the standard library with PLAIN auth ; no third-party SMTP client. HTML bodies are supported via the Options-less Send signature : pass body that starts with "<" (after trimming) and we emit Content-Type: text/html ; otherwise text/plain. Both shapes set the standard MIME-Version + Date + Message-ID headers so well-behaved MTAs don't tag the message as suspicious.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopSender

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

NoopSender swallows the delivery. It exists so callers don't have to nil-check the Sender on every call site ; the log line is the dev-mode signal that "we would have sent something here".

func (*NoopSender) Send

func (n *NoopSender) Send(_ context.Context, to []string, subject, _ string) error

Send logs the intended delivery and returns nil. Never errors.

type Options

type Options struct {
	// SMTPHost is the relay's hostname. Empty disables outbound mail.
	SMTPHost string
	// SMTPPort is the TCP port (typically 587 for STARTTLS submission
	// or 25 for plain). Defaults to 587 when zero and SMTPHost is set.
	SMTPPort int
	// Username is the PLAIN auth identity ; usually identical to From.
	Username string
	// Password is the PLAIN auth secret. Never logged.
	Password string
	// From is the envelope sender + the From: header value.
	From string
}

Options bundles the SMTP parameters. The zero value (SMTPHost empty) selects the NoopSender path.

type SMTPSender

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

SMTPSender uses net/smtp's stdlib client. PLAIN auth ; STARTTLS is negotiated automatically by net/smtp when the server advertises it over the standard submission port.

func (*SMTPSender) Send

func (s *SMTPSender) Send(ctx context.Context, to []string, subject, body string) error

Send dispatches one message to every address in `to`. The body is rendered as text/html when it begins with "<" (after trimming) ; otherwise text/plain.

Errors from net/smtp are wrapped with a "email send: " prefix so the call site logs surface the SMTP context — net/smtp's raw error strings (e.g. "wsa connect failed") aren't great in isolation.

ctx is honoured only on the "should we even try" check (cancelled → return ctx.Err()). The SMTP dialogue itself runs net/smtp's blocking code path ; tightening that to ctx requires a custom dialer + Client that's out of scope for the initial wiring.

type Sender

type Sender interface {
	Send(ctx context.Context, to []string, subject, body string) error
}

Sender is the contract the API handlers depend on. Send is allowed to block for the duration of an SMTP dialogue ; callers either goroutine the call or accept the latency budget (single-recipient transactional mail is typically < 500 ms against a nearby relay).

func NewSender

func NewSender(o Options, log *slog.Logger) Sender

NewSender wires the appropriate Sender from Options. Empty SMTPHost selects the NoopSender ; otherwise the SMTPSender.

log may be nil — both implementations no-op the logging when it is, which keeps the test surface tiny.

Jump to

Keyboard shortcuts

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