mail

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package mail sends the panel's transactional e-mails (address verification, sign-in codes, password reset, test message) over SMTP with net/smtp: implicit TLS, STARTTLS or plain, PLAIN/LOGIN authentication, and multipart/alternative (text + minimal HTML) bodies.

Index

Constants

View Source
const (
	LocaleEN      = "en"
	LocaleRU      = "ru"
	DefaultLocale = LocaleEN
)

Locales with templates; anything else falls back to DefaultLocale.

Variables

View Source
var ErrNotConfigured = errors.New("mail: SMTP is not configured")

ErrNotConfigured is returned when no SMTP host is set.

Functions

func Build

func Build(from, to *mail.Address, m Message, now time.Time) ([]byte, error)

Build renders the RFC 5322 message (CRLF line endings).

func NormalizeLocale

func NormalizeLocale(s string) string

NormalizeLocale maps "ru-RU", "RU" etc. to a supported locale ("" when unsupported).

func Validate

func Validate(cfg config.SMTPConfig) error

Validate checks the fields Send relies on.

Types

type Data

type Data struct {
	// Title is the panel name (branding title).
	Title    string
	Username string
	// Code is the one-time code (verify_email, login_code).
	Code string
	// Link is the password reset link.
	Link string
	// Minutes is the validity of the code or link.
	Minutes int
	// IP is the client address that triggered the e-mail.
	IP string
}

Data fills a template.

type Kind

type Kind string

Kind selects a transactional template.

const (
	KindTest          Kind = "test"
	KindVerifyEmail   Kind = "verify_email"
	KindLoginCode     Kind = "login_code"
	KindPasswordReset Kind = "password_reset"
)

Templates.

type Message

type Message struct {
	To      string
	Subject string
	Text    string
	// HTML is optional; when set the body is multipart/alternative.
	HTML string
}

Message is one e-mail to a single recipient.

func Render

func Render(kind Kind, locale string, d Data) (Message, error)

Render builds the subject and bodies of kind in locale (fallback: en).

type SMTP

type SMTP struct {
	Config config.SMTPConfig
	// Now is the clock for the Date header (default time.Now).
	Now func() time.Time
}

SMTP is a Sender for one server configuration.

func NewSMTP

func NewSMTP(cfg config.SMTPConfig) *SMTP

NewSMTP returns a Sender delivering through cfg.

func (*SMTP) Send

func (s *SMTP) Send(ctx context.Context, m Message) error

Send implements Sender.

type Sender

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

Sender delivers messages.

type SenderFunc

type SenderFunc func(ctx context.Context, m Message) error

SenderFunc adapts a function to Sender.

func (SenderFunc) Send

func (f SenderFunc) Send(ctx context.Context, m Message) error

Send implements Sender.

Directories

Path Synopsis
Package mailtest is an in-process fake SMTP server for tests: it speaks enough ESMTP (EHLO, STARTTLS, AUTH PLAIN/LOGIN, MAIL, RCPT, DATA) for net/smtp and records every accepted message.
Package mailtest is an in-process fake SMTP server for tests: it speaks enough ESMTP (EHLO, STARTTLS, AUTH PLAIN/LOGIN, MAIL, RCPT, DATA) for net/smtp and records every accepted message.

Jump to

Keyboard shortcuts

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