mailsettings

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package mailsettings stores the SMTP settings an owner saves in the admin. The password is sealed with the server secret; a missing row means the server's SMTP_* environment applies.

Index

Constants

View Source
const (
	ProviderCustom = "custom"
	ProviderSES    = "ses"
	ProviderGmail  = "gmail"
)

Providers (presets). The preset decides the host for SES and Gmail.

View Source
const (
	MaxHostLen     = 253
	MaxUsernameLen = 255
	MaxAddressLen  = 254
	MaxFromNameLen = 200
)

Field length limits.

View Source
const DefaultSESRegion = "us-east-1"

DefaultSESRegion is preselected for the Amazon SES preset.

View Source
const GmailHost = "smtp.gmail.com"

GmailHost is the SMTP host of the Gmail / Google Workspace preset.

Variables

Providers lists the valid provider values.

View Source
var SESRegions = []string{
	"us-east-1", "us-east-2", "us-west-1", "us-west-2",
	"ca-central-1", "sa-east-1",
	"eu-west-1", "eu-west-2", "eu-west-3", "eu-central-1", "eu-north-1", "eu-south-1",
	"ap-south-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3",
	"ap-southeast-1", "ap-southeast-2",
}

SESRegions is the closed list of regions the SES preset offers.

Functions

func IsLoopbackHost

func IsLoopbackHost(host string) bool

IsLoopbackHost reports whether host is one of the three names Go's smtp.PlainAuth accepts without TLS: "localhost", "127.0.0.1" and "::1", compared exactly (callers lower-case the host first). Security "none" is only accepted for these, so a wider rule would pass validation and then fail at AUTH.

func PasswordKey

func PasswordKey(serverSecret string) []byte

PasswordKey derives the key that seals the password from the server secret.

func SESHost

func SESHost(region string) string

SESHost returns the SMTP endpoint for an Amazon SES region.

func SealPassword

func SealPassword(key []byte, password string) ([]byte, error)

SealPassword returns the sealed form of a password for Settings.PasswordSealed.

Types

type Querier

type Querier interface {
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}

Querier is the part of a pgx pool the Store needs.

type Settings

type Settings struct {
	Provider       string
	SESRegion      string // only for ProviderSES
	Host           string
	Port           int
	Security       email.Security
	Username       string
	PasswordSealed []byte // sealed password; nil when none is saved
	FromAddress    string
	FromName       string    // blank = follow the site name
	UpdatedAt      time.Time // set by the database
}

Settings is the saved SMTP configuration.

func (Settings) EmailConfig

func (s Settings) EmailConfig(password string) email.Config

EmailConfig builds the service configuration for these settings with the opened password. Saved settings may use host "localhost".

func (Settings) HasPassword

func (s Settings) HasPassword() bool

HasPassword reports whether a sealed password is stored.

func (Settings) Password

func (s Settings) Password(key []byte) (password string, ok bool)

Password opens the stored password. ok is false when none is saved or it cannot be read (the server's secret changed); use HasPassword to tell the two apart.

func (Settings) Validate

func (s Settings) Validate() error

Validate checks every field against its allowed values.

type Store

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

Store reads and writes the single hatamoto_smtp_settings row. It does not cache: it is read at boot, after each admin change and by the replica convergence check, never per request.

func NewStore

func NewStore(db Querier) *Store

NewStore returns a Store over db (a *pgxpool.Pool fits).

func (*Store) Clear

func (s *Store) Clear(ctx context.Context) error

Clear deletes the saved row so the server's environment applies again.

func (*Store) Get

func (s *Store) Get(ctx context.Context) (set Settings, found bool, err error)

Get returns the saved settings; found is false when no row exists.

func (*Store) Save

func (s *Store) Save(ctx context.Context, set Settings) error

Save validates set and stores it as the single row.

Jump to

Keyboard shortcuts

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