smtp

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSendTimeout = 30 * time.Second

DefaultSendTimeout bounds one SMTP conversation when the caller's context carries no deadline of its own. See Sender for the context contract.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	Username string
	Password string
	From     string

	// SendTimeout caps each send (zero = DefaultSendTimeout). Raise it for
	// slow relays; it exists so a hanging SMTP server cannot pin a goroutine
	// forever once the caller's deadline is deliberately ignored.
	SendTimeout time.Duration
}

type InviteData added in v0.8.0

type InviteData = mailtpl.InviteData

Copy machinery lives in mailtpl so every email adapter (resend …) shares one template set. The aliases below keep the historical notifysmtp.* names source-compatible: notifysmtp.Templates IS mailtpl.Templates.

type LinkData added in v0.8.0

type LinkData = mailtpl.LinkData

Copy machinery lives in mailtpl so every email adapter (resend …) shares one template set. The aliases below keep the historical notifysmtp.* names source-compatible: notifysmtp.Templates IS mailtpl.Templates.

type LoginCodeData added in v0.8.0

type LoginCodeData = mailtpl.LoginCodeData

Copy machinery lives in mailtpl so every email adapter (resend …) shares one template set. The aliases below keep the historical notifysmtp.* names source-compatible: notifysmtp.Templates IS mailtpl.Templates.

type Sender

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

Sender sends templated email over SMTP. Context contract (shuijing field report, 2026-10-25): every send method DETACHES from the caller's cancellation and deadline — the ctx passed in by an HTTP handler carries the request timeout (typically 5s), and a slow SMTP relay used to get the login code killed mid-send: the mail lost AND the request failed. Sends keep only the ctx VALUES (request id, tenant values) and run under their own timeout (Config.SendTimeout, default 30s): better late than lost. Callers that need to bound a send should set Config.SendTimeout, not a request-scoped ctx.

func New

func New(cfg Config, log *slog.Logger) *Sender

New builds a Sender with the built-in Chinese copy (zero-value Templates).

func NewWithTemplates added in v0.8.0

func NewWithTemplates(cfg Config, tpl Templates, log *slog.Logger) (*Sender, error)

NewWithTemplates builds a Sender with a custom copy set. All templates are parsed once here; a parse failure fails construction (fail-fast). Empty Subject/Body fields fall back to the built-in Chinese defaults.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, to, subject, body string) error

func (*Sender) SendEmailVerification

func (s *Sender) SendEmailVerification(ctx context.Context, to, link string) error

func (*Sender) SendInvite

func (s *Sender) SendInvite(ctx context.Context, to, workspaceName, invitationID string) error

func (*Sender) SendLoginCode

func (s *Sender) SendLoginCode(ctx context.Context, to, code string) error

func (*Sender) SendPasswordReset

func (s *Sender) SendPasswordReset(ctx context.Context, to, link string) error

type Template added in v0.8.0

type Template = mailtpl.Template

Copy machinery lives in mailtpl so every email adapter (resend …) shares one template set. The aliases below keep the historical notifysmtp.* names source-compatible: notifysmtp.Templates IS mailtpl.Templates.

type Templates added in v0.8.0

type Templates = mailtpl.Templates

Copy machinery lives in mailtpl so every email adapter (resend …) shares one template set. The aliases below keep the historical notifysmtp.* names source-compatible: notifysmtp.Templates IS mailtpl.Templates.

Jump to

Keyboard shortcuts

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