accounts/api/email.go
Haitao Pan ee6e1a6363 feat: move account service to repo root
# Conflicts:
#	account/Makefile
#	account/go.mod
#	docs/account-admin-settings.md
#	docs/account-svc-plus.md
2026-01-16 16:15:23 +08:00

37 lines
872 B
Go

package api
import (
"context"
"log/slog"
)
// EmailMessage represents the contents of an email notification.
type EmailMessage struct {
To []string
Subject string
PlainBody string
HTMLBody string
}
// EmailSender sends email notifications.
type EmailSender interface {
Send(ctx context.Context, msg EmailMessage) error
}
// EmailSenderFunc adapts a function so it can be used as an EmailSender.
type EmailSenderFunc func(ctx context.Context, msg EmailMessage) error
// Send implements EmailSender.
func (f EmailSenderFunc) Send(ctx context.Context, msg EmailMessage) error {
if f == nil {
return nil
}
return f(ctx, msg)
}
var noopEmailSender EmailSender = EmailSenderFunc(func(ctx context.Context, msg EmailMessage) error {
_ = ctx
slog.Warn("email sender not configured; suppressing email delivery", "subject", msg.Subject)
return nil
})