mailer

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mailer sends transactional email through a pluggable Sender.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(htmlSrc, textSrc string, data any) (string, string, error)

Render executes the HTML and text templates with data and returns both rendered bodies.

Types

type LogSender

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

LogSender logs the recipient and subject instead of sending. Dev fallback.

func NewLogSender

func NewLogSender() *LogSender

NewLogSender returns a LogSender backed by the default logger.

func (*LogSender) Send

func (s *LogSender) Send(ctx context.Context, msg Message) error

Send logs the message metadata and returns nil.

type MemorySender

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

MemorySender captures sent messages for tests.

func (*MemorySender) Messages

func (s *MemorySender) Messages() []Message

Messages returns a copy of the captured messages.

func (*MemorySender) Send

func (s *MemorySender) Send(ctx context.Context, msg Message) error

Send records msg.

type Message

type Message struct {
	To      []string `json:"to"`
	Subject string   `json:"subject"`
	HTML    string   `json:"html,omitempty"`
	Text    string   `json:"text,omitempty"`
}

Message is a single email. It is JSON-serializable so it can double as a job payload.

type SMTPConfig

type SMTPConfig struct {
	Host     string
	Port     int
	Username string
	Password string
	From     string
}

SMTPConfig configures the SMTP sender.

type SMTPSender

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

SMTPSender sends via go-mail over SMTP.

func NewSMTP

func NewSMTP(cfg SMTPConfig) (*SMTPSender, error)

NewSMTP builds an SMTP sender. SMTP auth is used only when Username is set; TLS is opportunistic (works against a local mailhog as well as real servers).

func (*SMTPSender) Send

func (s *SMTPSender) Send(ctx context.Context, msg Message) error

Send delivers msg over SMTP.

type Sender

type Sender interface {
	Send(ctx context.Context, msg Message) error
}

Sender delivers a Message.

func New

func New(cfg SMTPConfig) (Sender, error)

New returns an SMTPSender when cfg.Host is set, otherwise a LogSender (fail-soft dev default).

Jump to

Keyboard shortcuts

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