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".
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 ¶
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.