smtp

package
v0.0.0-...-95891f2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package smtp provides outbound email functionality for Chronicle. SMTP settings are stored in the database and managed by site admins. The encrypted password is NEVER returned to the UI -- only a boolean indicating whether a password is configured.

Index

Constants

View Source
const PluginHealthKey = "smtp"

PluginHealthKey is the identifier the database.PluginHealthRegistry uses for this plugin. Kept separate from PluginSlug so cross-package callers stay symmetric with plugins where the two values differ (e.g. foundry_vtt).

View Source
const PluginSlug = "smtp"

PluginSlug is the canonical identifier for the smtp plugin in the App's PluginRegistration registry. Its routes are mounted from inside admin.RegisterRoutes, not from here.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(adminGroup *echo.Group, h *Handler, reauth echo.MiddlewareFunc)

RegisterRoutes sets up SMTP admin routes on the given admin route group. All routes require site admin middleware (applied by the caller). reauth guards the writes that repoint outgoing mail or send it: whoever controls the mail server receives every password-reset link.

Types

type ActivityRecorder

type ActivityRecorder interface {
	RecordAdminChange(c *echo.Context, action, targetType, targetID, label string)
}

ActivityRecorder is the slice of the admin change log this plugin writes to. It is declared here, not imported from the admin plugin, so the plugins stay independent; app wiring supplies an adapter that stamps the signed-in admin. Recording is best-effort: implementations must not fail the request.

type Handler

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

Handler handles HTTP requests for SMTP settings management. Admin-only -- all routes require site admin middleware.

func NewHandler

func NewHandler(service SMTPService) *Handler

NewHandler creates a new SMTP handler.

func (*Handler) SendTestEmail

func (h *Handler) SendTestEmail(c *echo.Context) error

SendTestEmail sends a test email to a specified address (POST /admin/smtp/send-test).

func (*Handler) SetActivityRecorder

func (h *Handler) SetActivityRecorder(r ActivityRecorder)

SetActivityRecorder wires the admin change log. Optional: nil disables it.

func (*Handler) Settings

func (h *Handler) Settings(c *echo.Context) error

Settings renders the SMTP settings page (GET /admin/smtp).

func (*Handler) TestConnection

func (h *Handler) TestConnection(c *echo.Context) error

TestConnection tests SMTP connectivity (POST /admin/smtp/test).

func (*Handler) UpdateSettings

func (h *Handler) UpdateSettings(c *echo.Context) error

UpdateSettings saves SMTP settings (PUT /admin/smtp).

type Mail

type Mail struct {
	To      []string
	Subject string
	Body    string
}

Mail represents an email message to be sent.

type MailService

type MailService interface {
	SendMail(ctx context.Context, to []string, subject, body string) error
	SendHTMLMail(ctx context.Context, to []string, subject, plainBody, htmlBody string) error
	IsConfigured(ctx context.Context) bool
}

MailService is the interface other plugins use to send email. This is the cross-plugin contract -- campaigns uses this for transfer emails.

type SMTPRepository

type SMTPRepository interface {
	// Get returns the SMTP settings row including encrypted password bytes.
	Get(ctx context.Context) (*smtpRow, error)

	// Upsert updates the SMTP settings. Uses INSERT ... ON DUPLICATE KEY UPDATE
	// to handle the singleton pattern.
	Upsert(ctx context.Context, row *smtpRow) error
}

SMTPRepository handles database operations for SMTP settings. This is a singleton table (id=1) so all operations target that row.

func NewSMTPRepository

func NewSMTPRepository(db *sql.DB) SMTPRepository

NewSMTPRepository creates a new SMTP repository.

type SMTPService

type SMTPService interface {
	MailService

	// GetSettings returns the SMTP configuration (password redacted).
	GetSettings(ctx context.Context) (*SMTPSettings, error)

	// UpdateSettings saves new SMTP settings. Empty password keeps existing.
	UpdateSettings(ctx context.Context, req UpdateSMTPRequest) error

	// TestConnection verifies SMTP connectivity with current settings.
	TestConnection(ctx context.Context) error

	// SendTestEmail sends a test email to the given address using current settings.
	SendTestEmail(ctx context.Context, to string) error
}

SMTPService extends MailService with admin settings management.

func NewSMTPService

func NewSMTPService(repo SMTPRepository, secretKey string) SMTPService

NewSMTPService creates a new SMTP service.

type SMTPSettings

type SMTPSettings struct {
	Host        string    `json:"host"`
	Port        int       `json:"port"`
	Username    string    `json:"username"`
	HasPassword bool      `json:"has_password"` // True if encrypted password exists.
	FromAddress string    `json:"from_address"`
	FromName    string    `json:"from_name"`
	Encryption  string    `json:"encryption"` // "starttls", "ssl", or "none".
	Enabled     bool      `json:"enabled"`
	UpdatedAt   time.Time `json:"updated_at"`
}

SMTPSettings holds the SMTP configuration. This is what the service layer and handlers work with. The password is intentionally omitted -- use HasPassword to show whether one is set.

type UpdateSMTPRequest

type UpdateSMTPRequest struct {
	Host        string `json:"host" form:"host"`
	Port        int    `json:"port" form:"port"`
	Username    string `json:"username" form:"username"`
	Password    string `json:"password" form:"password"` // Empty = keep existing.
	FromAddress string `json:"from_address" form:"from_address"`
	FromName    string `json:"from_name" form:"from_name"`
	Encryption  string `json:"encryption" form:"encryption"`
	Enabled     bool   `json:"enabled" form:"enabled"`
}

UpdateSMTPRequest holds form data for updating SMTP settings. Password is optional -- empty means "keep existing".

Jump to

Keyboard shortcuts

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