smtp

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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
}

type InviteData added in v0.8.0

type InviteData struct {
	Workspace    string
	InvitationID string
}

InviteData is the data fed to the Invite templates. InvitationID is part of the default body ("邀请标识:…"), so it travels with the workspace name.

type LinkData added in v0.8.0

type LinkData struct {
	Link string
}

LinkData is the data fed to the PasswordReset and EmailVerification templates.

type LoginCodeData added in v0.8.0

type LoginCodeData struct {
	Code string
}

LoginCodeData is the data fed to the LoginCode templates.

type Sender

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

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 struct {
	Subject string
	Body    string
}

Template is one renderable piece of email copy: a subject plus a plain-text body, both text/template sources. An empty Subject or Body means "use the built-in Chinese default for that piece", so the zero-value Templates reproduces the original hardcoded copy byte for byte.

type Templates added in v0.8.0

type Templates struct {
	LoginCode         Template
	Invite            Template
	PasswordReset     Template
	EmailVerification Template
}

Templates is the injectable copy set for the four templated send methods. Per-locale selection stays product-side: the product compiles the copy it wants and passes it to NewWithTemplates.

Each group is executed with exactly the data its method carries:

  • LoginCode: LoginCodeData{Code}
  • Invite: InviteData{Workspace, InvitationID}
  • PasswordReset: LinkData{Link}
  • EmailVerification: LinkData{Link}

Referencing a field outside the group's data (e.g. {{.Link}} in a LoginCode body) fails the send at render time.

Jump to

Keyboard shortcuts

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