email

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 8 Imported by: 0 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudflareSender

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

CloudflareSender sends login emails via the Cloudflare Email Sending REST API.

func NewCloudflareSender

func NewCloudflareSender(cfg EmailConfig) (*CloudflareSender, error)

NewCloudflareSender constructs a CloudflareSender from cfg. Returns an error if accountID, apiToken, or fromAddress are missing.

func (s *CloudflareSender) SendLoginLink(ctx context.Context, msg LoginEmail) error

SendLoginLink sends a magic-link login email via the Cloudflare Email Sending API.

Security constraints:

  • The API token is never included in any returned error.
  • msg.HTML, msg.Text, and msg.Subject (which may contain the magic link token) are never logged.

type EmailConfig

type EmailConfig struct {
	Provider  string // "cloudflare", "memory", "log"
	AccountID string // Cloudflare account ID
	APIToken  string // Cloudflare Email Workers API token
	From      string // e.g. login@example.com
	FromName  string // e.g. td-watch
	ReplyTo   string // e.g. support@example.com
	// CloudflareBaseURL overrides the Cloudflare REST API base. Tests-only.
	// Empty => https://api.cloudflare.com/client/v4. WARNING: do NOT set this to
	// td-sync's own base URL (SYNC_EMAIL_BASE_URL) — that points email sends at
	// the wrong host (causes 404 "unexpected status").
	CloudflareBaseURL string
	CallbackURL       string // e.g. https://watch.example.com/home/login/complete
}

EmailConfig holds the fields that email senders need. The mapping from api.Config to EmailConfig is done in the api/cmd layer to avoid import cycles.

type EmailSender

type EmailSender interface {
	SendLoginLink(ctx context.Context, msg LoginEmail) error
}

EmailSender is the provider-neutral interface for sending login emails.

func NewEmailSender

func NewEmailSender(cfg EmailConfig) (EmailSender, error)

NewEmailSender constructs the appropriate EmailSender for cfg.Provider. Recognised values: "cloudflare", "memory", "log", "" (empty string treated as "log").

type LogSender

type LogSender struct{}

LogSender logs a structured record for each login email. It intentionally omits Subject, Text, and HTML because those fields carry the magic link token.

func NewLogSender

func NewLogSender() *LogSender

NewLogSender returns a LogSender.

func (s *LogSender) SendLoginLink(ctx context.Context, msg LoginEmail) error

SendLoginLink logs To, Purpose, and TraceID via slog. Token material (Subject, Text, HTML) is never logged.

type LoginEmail

type LoginEmail struct {
	To      string
	Subject string
	Text    string
	HTML    string
	Purpose string // e.g. "web_login", "device_login"
	TraceID string
}

LoginEmail holds the data for a magic-link login email.

type MemorySender

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

MemorySender stores sent emails in memory. Intended for tests and local dev.

func NewMemorySender

func NewMemorySender() *MemorySender

NewMemorySender returns an empty MemorySender.

func (*MemorySender) Last

func (s *MemorySender) Last() (LoginEmail, bool)

Last returns the most recently sent email and true, or a zero LoginEmail and false when nothing has been sent yet. It returns a copy, so the caller cannot mutate the buffered message.

func (s *MemorySender) SendLoginLink(_ context.Context, msg LoginEmail) error

SendLoginLink appends msg to the in-memory store.

func (*MemorySender) Sent

func (s *MemorySender) Sent() []LoginEmail

Sent returns a copy of all emails that have been sent so far.

Jump to

Keyboard shortcuts

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