mail

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mail sends transactional email over SMTP (STARTTLS, implicit TLS or plain) with the standard library, and renders the panel's email templates in English and Indonesian.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(cfg Settings, msg Message, now time.Time) []byte

Build renders msg as a MIME message (multipart/alternative when HTML is present).

func Templates

func Templates() []string

Templates lists the template names (for tests).

Types

type Message

type Message struct {
	To      string
	Subject string
	Text    string
	HTML    string
}

Message is one email.

func Render

func Render(name, locale string, data map[string]string) (Message, error)

Render builds the message for template name in locale (falls back to English). data values are plain text; "link" is the button target, "site" the panel name.

type SMTP

type SMTP struct {
	// Dial overrides the TCP dial (tests).
	Dial func(ctx context.Context, addr string) (net.Conn, error)
}

SMTP sends through the configured server.

func (SMTP) Send

func (c SMTP) Send(ctx context.Context, cfg Settings, msg Message) error

Send delivers msg.

type Sender

type Sender interface {
	Send(ctx context.Context, cfg Settings, msg Message) error
}

Sender delivers messages (replaced in tests).

type Settings

type Settings struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
	// Security: "starttls" (port 587), "tls" (implicit TLS, port 465) or "none" (local relay only).
	Security string `json:"security"`
	From     string `json:"from"`
	FromName string `json:"from_name"`
	// RequireVerification makes customers confirm their email before ordering.
	RequireVerification bool `json:"require_verification"`
}

Settings is the SMTP configuration (stored in the settings table under "mail").

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings: not configured, verification required once it is.

func (Settings) Configured

func (s Settings) Configured() bool

Configured reports whether email can be sent.

func (Settings) Validate

func (s Settings) Validate() error

Validate checks the settings before they are saved.

Jump to

Keyboard shortcuts

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