Help us shape the future of Go! Take the 2026 Go Developer Survey

notifyrender

package
v1.149.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package notifyrender turns queued notifications into branded multipart emails. It owns the embedded templates, the deployment branding they render with, and the Email value a sender delivers.

Rendering is the only layer that decides what a message looks like: the worker hands it a claimed batch and passes the result to a sender unchanged, so every message the platform emits carries the same footer, logo and Reply-To treatment.

Index

Constants

View Source
const LogoContentID = "logo.png"

LogoContentID is the Content-ID of the inline logo part. The HTML template references it as cid:<this>, so the two must stay in sync.

Variables

This section is empty.

Functions

func AlertDocument added in v1.143.0

func AlertDocument(p notification.Payload) notification.Document

AlertDocument renders a platform alert's payload as the document a channel carries: the line its email's subject carries as the title, the prose its email's body carries as the body, and its link. A channel reader and an email reader are told the same thing in the same words.

func Subject

func Subject(n notification.Notification) string

Subject returns the one-line summary of a single notification: the subject its email carries, and the same line the admin monitoring tab and a user's own notification history show for the row.

Those surfaces read it from here rather than composing their own so a reader comparing a queue row against the mail they received sees one sentence, not two spellings of it.

Types

type AttachmentLink struct {
	Name string
	URL  string
}

AttachmentLink is an attachment a message names by link instead of carrying: one over the size a file may be, or one that could not be read.

type Branding

type Branding struct {
	// Name is the portal brand/title, e.g. "ACME Data Platform".
	Name string
	// BaseURL is the portal's public base URL used for deep links.
	BaseURL string
	// ImplementorName and ImplementorURL render in the footer when set.
	ImplementorName string
	ImplementorURL  string
	// TermsURL and PrivacyURL render as small legal links in the footer when
	// set. When the portal runs on a different domain than the mail From
	// address, they give recipients and content filters body links that
	// associate with the sending identity.
	TermsURL   string
	PrivacyURL string
	// AboutText and SupportContact render as a help/about footer block on
	// all outgoing mail when set (#1023). AboutText is a sentence or two
	// describing the platform; SupportContact is an email address or http(s)
	// URL for help. Implementor-owned YAML config (portal.about_text,
	// portal.support_contact), like the rest of the branding: in fully
	// managed deployments these are not admin-editable.
	AboutText      string
	SupportContact string
	// ReplyTo, when set, is stamped on every rendered Email so the sender
	// applies it as the Reply-To header and recipient replies reach a
	// monitored mailbox (#1023). From portal.reply_to.
	ReplyTo string
	// LogoPNG is the raster logo from portal.logo_email, resolved once at
	// startup. When non-empty it is attached to every message as an inline
	// (cid:) part and rendered above the wordmark; recipients never fetch it
	// remotely, so it survives the image blocking most clients apply by
	// default. Empty renders the wordmark alone.
	LogoPNG []byte
}

Branding carries the deployment identity emails render with. Values come from the same PortalConfig the portal UI uses, so emails match the portal. The brand name always renders as a styled wordmark linked to BaseURL; the portal's SVG logo is never usable here because email clients strip inline SVG, so LogoPNG carries a separate raster asset when the operator supplies one.

type Email

type Email struct {
	To      string
	Subject string
	HTML    string
	Text    string
	// LogoPNG is the inline logo the sender must attach under LogoContentID
	// when non-empty. The HTML references it but cannot carry the bytes.
	LogoPNG []byte
	// UnsubURL is the recipient's no-login unsubscribe link when the message
	// carries the footer opt-out (notifications only; transactional sends
	// leave it empty). The sender emits the RFC 8058 List-Unsubscribe headers
	// from it, so header presence tracks the footer link exactly.
	UnsubURL string
	// ReplyTo is the Reply-To address the sender must apply when non-empty
	// (#1023). Stamped from Branding.ReplyTo on every rendered message.
	ReplyTo string
	// Attachments are files the sender attaches as MIME parts: a channel
	// document's attachments, read at delivery.
	Attachments []notification.File
}

Email is one rendered message ready for an SMTP sender.

type Renderer

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

Renderer renders queued notifications into branded multipart emails.

func NewRenderer

func NewRenderer(b Branding) (*Renderer, error)

NewRenderer parses the embedded templates for the given branding.

func (*Renderer) Render

func (r *Renderer) Render(ns []notification.Notification) (*Email, error)

Render renders one email covering the given notifications. A single notification renders the per-event template; multiple render the digest layout. All notifications must target the same recipient.

func (*Renderer) RenderDocument added in v1.143.0

func (r *Renderer) RenderDocument(n notification.Notification, files []notification.File, links []AttachmentLink) (*Email, error)

RenderDocument renders one channel document to one email recipient with its attachments: files is what travels as MIME parts, links what the message names by link instead.

func (*Renderer) RenderExternalSignIn added in v1.149.0

func (r *Renderer) RenderExternalSignIn(m SignIn) (*Email, error)

RenderExternalSignIn renders the email that holds an external user's one-time sign-in link (#2092): their invitation, or a link they asked for on the sign-in screen.

func (r *Renderer) RenderGuestLink(to, link string) (*Email, error)

RenderGuestLink renders the one-time view link email a share recipient requests from the landing page (#1001). It is transactional, not a notification: the recipient asked for it, so it carries no unsubscribe footer and its delivery bypasses the queue and preference gating.

func (*Renderer) RenderTest

func (r *Renderer) RenderTest(to string) (*Email, error)

RenderTest renders the admin "send test email" message used to verify a new SMTP configuration end to end.

func (*Renderer) SetUnsubscribeURLFn

func (r *Renderer) SetUnsubscribeURLFn(fn func(email string) string)

SetUnsubscribeURLFn installs the builder for the footer's no-login unsubscribe link. The composition root supplies it when it can mint the HMAC tokens the endpoint verifies; without it emails keep only the signed-in preferences link.

type SignIn added in v1.149.0

type SignIn struct {
	To, Name, Link string
	Invitation     bool
	Valid          time.Duration
}

SignIn is an external user's sign-in email (#2092): the invitation when Invitation is true, a link the person asked for otherwise. Valid is how long the link works.

Jump to

Keyboard shortcuts

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