onboardmail

package
v0.36.21 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package onboardmail sends the welcome email and the setup reminders: at most three emails per user ever (one welcome, two reminders), only to a verified address, only until the truck is connected and sending data, and never after the user opted out. Every email carries a signed one-click unsubscribe link and List-Unsubscribe headers. No tracking pixel, no rewritten links.

Index

Constants

View Source
const (
	NudgeMinAge   = 72 * time.Hour
	NudgeFollowUp = 6 * 24 * time.Hour
)

Timing of the setup reminders: the first once the account is three days old, the follow-up six days after the first.

View Source
const UnsubPurpose = "onboarding"

UnsubPurpose is the token "period" that scopes a signed link to these emails: the statement email's unsubscribe only accepts YYYY-MM.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	Subject, Text  string
	Key            string // idempotency key prefix (Resend dedupes for 24 h)
	Attempt        int
	UnsubscribeURL string
}

Content is one email to send.

func Nudge

func Nudge(kind string, attempt int, l Links) Content

Nudge is a setup reminder. kind is db.NudgeNoVehicle or db.NudgeNoData; attempt is 1 or 2.

func Welcome

func Welcome(l Links) Content

Welcome is the day-0 email.

type Job

type Job struct {
	DB   *sql.DB
	Mail Sender
	// Signer returns the unsubscribe-link signer, or nil: then nothing is
	// sent (no way to unsubscribe). A func because the signer is built after
	// the sweep is wired.
	Signer  func() *statement.Signer
	BaseURL string
	Logger  *slog.Logger
	Now     func() time.Time
	// OnSent, when set, is told after each send (metrics, funnel log).
	OnSent func(kind string, attempt int, uid uuid.UUID)
}

Job sweeps for users due a welcome or a reminder and sends it.

func (*Job) Sweep

func (j *Job) Sweep(ctx context.Context) (welcomes, nudges int)

Sweep runs one pass and returns how many welcomes and reminders it sent.

type Links struct {
	App, Demo, Unsubscribe string
}

Links are the URLs an email may carry. App and Demo are empty when the install has no base URL configured.

type Sender

type Sender interface {
	Send(ctx context.Context, m email.Message) error
}

Sender is the part of the Resend client the job uses.

Jump to

Keyboard shortcuts

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