Documentation
¶
Index ¶
- Constants
- type Config
- type InviteData
- type LinkData
- type LoginCodeData
- type Sender
- func (s *Sender) Send(ctx context.Context, to, subject, body string) error
- func (s *Sender) SendEmailVerification(ctx context.Context, to, link string) error
- func (s *Sender) SendInvite(ctx context.Context, to, workspaceName, invitationID string) error
- func (s *Sender) SendLoginCode(ctx context.Context, to, code string) error
- func (s *Sender) SendPasswordReset(ctx context.Context, to, link string) error
- type Template
- type Templates
Constants ¶
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
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 NewWithTemplates ¶ added in v0.8.0
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.