mail

package
v3.42.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package mail sends glabs-web's job-notification emails. It keeps the go-mail dependency and the Markdown→text+HTML rendering confined here, so callers deal only with a small library-neutral surface (Config, Sender, Render, JobMail).

Every notification renders from a single Markdown template into both a text and an HTML part, so the two can never drift. SMTP credentials live in the server config file, never in the database.

Index

Constants

View Source
const (
	TmplScheduled    = "jobScheduled.md.tmpl"
	TmplDone         = "jobDone.md.tmpl"
	TmplFailed       = "jobFailed.md.tmpl"
	TmplExpired      = "jobExpired.md.tmpl"
	TmplAdminSummary = "adminSummary.md.tmpl"
)

Template file names for the four job-notification mails and the admin summary.

Variables

This section is empty.

Functions

func Render

func Render(name string, data any) (text, html []byte, err error)

Render renders the named Markdown template with data into the plain-text part (the Markdown itself, readable as-is, plus a footer) and the HTML part (Markdown → HTML wrapped in the shared base layout). One source feeds both, so they cannot drift. missingkey=error turns a template referencing an unknown field into an error instead of silently emitting "<no value>".

Types

type Config

type Config struct {
	Host     string
	Port     int
	Username string
	Password string
	// From is the address mails are sent as (the From header and, by default, the
	// SMTP envelope sender). Required.
	From string
	// Hostname is the FQDN used for the SMTP HELO/EHLO greeting and the Message-ID
	// domain. Empty falls back to defaultMailHostname; strict servers reject a
	// Message-ID derived from a container's os.Hostname().
	Hostname string
	// TLSInsecureSkipVerify disables server-certificate verification. Unlike
	// plexams (which hard-codes skip), this defaults to false — verify.
	TLSInsecureSkipVerify bool
	// TestRecipient receives dry-run sends and SendTest smoke tests.
	TestRecipient string
}

Config is the SMTP configuration, read from the server config in bootstrap. It is passed to NewSender; the mail package itself never touches viper.

type JobMail

type JobMail struct {
	Op         string
	Course     string
	Assignment string
	RunAt      time.Time
	GraceMin   int
	// Err is set for the failed/expired mails; Log carries the captured run output.
	Err string
	Log string
}

JobMail is the data a job-notification template renders. It is library-neutral, so the runner does not depend on anything mail-internal.

func SampleJob

func SampleJob() JobMail

SampleJob is representative data for SendTest and template tests.

type Sender

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

Sender sends rendered mails over SMTP. It is safe to build once and reuse.

func NewSender

func NewSender(cfg Config) *Sender

NewSender builds a Sender for the given SMTP configuration.

func (*Sender) Send

func (s *Sender) Send(dryRun bool, to, subject string, text, html []byte) error

Send delivers a rendered mail. dryRun is a mandatory choice, never a default: when true the mail goes to the configured TestRecipient with a [DRY-RUN] subject prefix and never to the real recipient. A dry-run without a TestRecipient is an error rather than a silent no-op.

func (*Sender) SendTest

func (s *Sender) SendTest() error

SendTest renders a representative job mail and sends it to the TestRecipient — a smoke test that the whole SMTP path works.

Jump to

Keyboard shortcuts

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