Help us shape the future of Go! Take the 2026 Go Developer Survey

mail

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package mail sends the application's email through the provider the administrators configure; SMTP is the one provider. It also holds the default subjects and HTML templates of the notification emails, which the stored configuration falls back to.

Index

Constants

View Source
const (
	DefaultEmailVerifySubject        = "Verification code"
	DefaultExpirationEmailSubject    = "Subscription Expired"
	DefaultMaintenanceEmailSubject   = "系统维护通知 / System Maintenance Notice"
	DefaultTrafficExceedEmailSubject = "Subscription Traffic Exceed"
)

Default subjects of the operator-configurable notification emails. Queue producers fall back to them when the admin config leaves the matching subject empty, which keeps existing deployments unchanged.

View Source
const (
	DefaultEmailVerifyTemplate = `` /* 3033-byte string literal not displayed */

	DefaultMaintenanceEmailTemplate = `` /* 2652-byte string literal not displayed */

	DefaultExpirationEmailTemplate = `` /* 2270-byte string literal not displayed */

	DefaultTrafficExceedEmailTemplate = `` /* 2083-byte string literal not displayed */

)

Default HTML templates of the notification emails, which the stored configuration falls back to like the subjects above. They are Go templates, bilingual in Chinese and English.

Variables

This section is empty.

Functions

func GetSupportedPlatforms

func GetSupportedPlatforms() []integration.Info

GetSupportedPlatforms describes the providers and their configuration fields for the administrators' settings page.

Types

type Platform

type Platform int

Platform is an email provider, stored in the configuration by its name.

const (
	// SMTP delivers through an SMTP relay.
	SMTP Platform = iota
)

func (Platform) String

func (p Platform) String() string

String returns the name the configuration stores p under.

type SMTPClient

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

SMTPClient sends through an SMTP relay, one connection per message.

func NewSMTPClient

func NewSMTPClient(conf *SMTPConfig) *SMTPClient

NewSMTPClient returns a client for conf, or nil for a nil conf.

func (*SMTPClient) SendContext added in v1.21.0

func (m *SMTPClient) SendContext(ctx context.Context, to []string, subject, body string) error

SendContext delivers the message over one SMTP conversation, bounded by ctx and by the client's own deadline. When ctx ends the conversation the error matches ctx's error; when the relay outlasts the client's deadline it is an ordinary delivery failure.

type SMTPConfig

type SMTPConfig struct {
	Host    string `json:"host"`
	Port    int    `json:"port"`
	User    string `json:"user"`
	Pass    string `json:"pass"`
	From    string `json:"from"`
	ReplyTo string `json:"reply_to"`
	// SSL requires encryption: implicit TLS on port 465 or with ImplicitTLS,
	// STARTTLS otherwise, refusing a relay that does not offer it. Unset,
	// STARTTLS stays opportunistic and a relay without TLS is used in the
	// clear.
	SSL      bool   `json:"ssl"`
	SiteName string `json:"siteName"`
	// ImplicitTLS starts the connection with a TLS handshake (SMTPS) on a
	// port other than 465, which is implicit TLS by definition. The relay and
	// submission ports (25, 587, 2525) start in plaintext and upgrade through
	// STARTTLS, so they never need it.
	ImplicitTLS bool `json:"implicit_tls"`
	// InsecureSkipVerify accepts any server certificate. It exists only for
	// relays with self-signed certificates and must be set explicitly in the
	// stored platform config; certificates are verified by default.
	InsecureSkipVerify bool `json:"insecure_skip_verify"`
}

SMTPConfig is the stored configuration of the SMTP provider; SiteName, the sender's display name, comes from the site settings instead.

type Sender

type Sender interface {
	// SendContext delivers an HTML body to the recipients. ctx bounds the
	// whole delivery; the provider applies its own deadline besides.
	SendContext(ctx context.Context, to []string, subject, body string) error
}

Sender delivers email through one provider account. It is safe for concurrent use.

func NewSender

func NewSender(platform, config, siteName string) (Sender, error)

NewSender builds the provider client for one provider configuration. config carries the provider credentials and must never be logged. Callers that send repeatedly keep their sender in a Senders cache.

type Senders added in v1.21.0

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

Senders keeps the sender built for the provider configuration in force, rebuilding it when the configuration or the site name changes. The zero value is ready.

func (*Senders) Get added in v1.21.0

func (s *Senders) Get(platform, config, siteName string) (Sender, error)

Get returns the sender for platform, config and siteName.

Jump to

Keyboard shortcuts

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