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 ¶
- func EmbeddedSource(name string) (string, error)
- func TemplateNames() ([]string, error)
- func Templates() embed.FS
- type Attachment
- type Renderer
- func (r *Renderer) List(ctx context.Context) ([]*model.EmailTemplate, error)
- func (r *Renderer) Render(name string, jira bool, data any) (text []byte, html []byte, err error)
- func (r *Renderer) Reset(ctx context.Context, name string) (bool, error)
- func (r *Renderer) Set(ctx context.Context, name, markdown string) (*model.EmailTemplate, error)
- type SMTPConfig
- type Sender
- type TemplateStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmbeddedSource ¶
EmbeddedSource returns the built-in source of a template by name (for the plexams-side attachment rendering and the parse guard).
func TemplateNames ¶
TemplateNames returns the sorted file names of the editable Markdown email body templates (the *.md.tmpl files; the emailBaseHTML/jiraOnHTML layout is not editable).
Types ¶
type Attachment ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
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.
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.