email

package
v1.213.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 14 Imported by: ? 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 is the email rendering toolkit: it turns a Markdown body template plus data into the plain-text and HTML parts of a mail, wrapped in the shared layout, and manages the DB-backed, editable per-template overrides. It is deliberately domain- and transport-agnostic: the caller injects the template functions and the JIRA-URL resolver (so shared helpers stay in plexams) and provides a TemplateStore for the overrides. The SMTP sending and the domain data gathering stay in the plexams package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmbeddedSource

func EmbeddedSource(name string) (string, error)

EmbeddedSource returns the built-in source of a template by name (for the plexams-side attachment rendering and the parse guard).

func TemplateNames

func TemplateNames() ([]string, error)

TemplateNames returns the sorted file names of the editable Markdown email body templates (the *.md.tmpl files; the emailBaseHTML/jiraOnHTML layout is not editable).

func Templates

func Templates() embed.FS

Templates exposes the embedded template FS (for callers that still render a template directly, e.g. the standalone Markdown attachment).

Types

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	Content     []byte
}

Attachment is a library-neutral mail attachment, so callers do not depend on the concrete mail library (the go-mail dependency stays confined to this package).

type Renderer

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

Renderer turns Markdown body templates + data into the text and HTML parts of a mail. Template funcs and the JIRA-URL resolver are injected so shared helpers stay in the caller (plexams); overrides come from the injected store (nil = embedded defaults only).

func New

func New(store TemplateStore, funcs map[string]any, jiraURL func() string) *Renderer

New builds a Renderer. store may be nil (then only embedded defaults are used, e.g. in tests). funcs is the template function set; jiraURL resolves the JIRA service-desk URL for the plain-text note (may be nil).

func (*Renderer) List

func (r *Renderer) List(ctx context.Context) ([]*model.EmailTemplate, error)

List returns every editable template with its effective Markdown, whether the built-in default is in use, and the default itself (for preview / reset).

func (*Renderer) Render

func (r *Renderer) Render(name string, jira bool, data any) (text []byte, html []byte, err error)

Render renders a Markdown body template and returns the plain-text part (the rendered Markdown, readable as-is) and the HTML part (Markdown → HTML wrapped in the shared base layout). The shared chrome (JIRA note / callout, footer) is added here for both parts so they cannot drift.

func (*Renderer) Reset

func (r *Renderer) Reset(ctx context.Context, name string) (bool, error)

Reset removes a template's override (revert to the built-in default).

func (*Renderer) Set

func (r *Renderer) Set(ctx context.Context, name, markdown string) (*model.EmailTemplate, error)

Set validates and stores a Markdown override for a known template. The Markdown must parse with the render func set, so a broken override can never reach a send.

type SMTPConfig

type SMTPConfig struct {
	Server   string
	Port     int
	Username string
	Password string
	// TestMail receives all dry-run sends (run == false); falls back to PlanerEmail.
	TestMail string
	// CC is added to the Cc of every real send (a shared/filterable mailbox).
	CC string
	// ReplyMail is the Reply-To for mails answerable by email; falls back to PlanerEmail.
	ReplyMail string
	// NoreplyMail is the Reply-To for JIRA-only mails; falls back to a noreply alias.
	NoreplyMail string
	PlanerName  string
	PlanerEmail string
}

SMTPConfig holds everything the Sender needs: the SMTP server credentials, the dry-run and Cc/Reply-To addresses, and the planner identity used as From / fallback recipient.

type Sender

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

Sender sends mails over SMTP and supports a dry-run collector that bundles a whole batch into one summary mail of .eml attachments.

func NewSender

func NewSender(cfg SMTPConfig) *Sender

NewSender builds a Sender for the given SMTP configuration.

func (*Sender) BeginCollection

func (s *Sender) BeginCollection()

BeginCollection starts capturing dry-run mails (replacing any stale collector). Pair every call with FlushCollection.

func (*Sender) FlushCollection

func (s *Sender) FlushCollection() (int, string, error)

FlushCollection sends the captured dry-run mails as one summary mail (each attached as an .eml) to the dry-run address, then clears the collector. Returns the number of mails and the recipient. A no-op (count 0) when no collector is active or nothing was captured.

func (*Sender) RecipientInfo

func (s *Sender) RecipientInfo(run bool, recipients ...string) string

RecipientInfo describes a send for progress/log output; on a dry run it makes explicit that the mail went to the dry-run address only and lists who it would have reached.

func (*Sender) Send

func (s *Sender) Send(run bool, to, cc []string, subject string, text, html []byte, attachments []*Attachment, jira bool) error

Send sends one mail. jira == true marks a mail answered via JIRA (Reply-To = noreply). On a real send the configured Cc is added. With a dry run (run == false): if a collector is active the mail is captured as .eml, otherwise it goes to the dry-run address with the real recipients prefixed into the subject.

func (*Sender) SendTest

func (s *Sender) SendTest() error

SendTest sends a fixed test mail to the planner (SMTP smoke test).

type TemplateStore

type TemplateStore interface {
	EmailTemplateOverride(ctx context.Context, name string) (string, bool, error)
	EmailTemplateOverrides(ctx context.Context) (map[string]string, error)
	SetEmailTemplateOverride(ctx context.Context, name, markdown string) error
	DeleteEmailTemplateOverride(ctx context.Context, name string) (bool, error)
}

TemplateStore persists per-template Markdown overrides (the editable layer over the embedded defaults). *db.DB satisfies it.

Jump to

Keyboard shortcuts

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