postmand

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package postmand sends transactional and marketing email through Mailpit, SMTP, or a logging sender, and renders the HTML/text template pairs exported by React Email.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsubscribeURLRequired = errors.New("marketing emails require unsubscribe URL")
	ErrMissingRecipient       = errors.New("missing recipient email address")
	ErrMissingSender          = errors.New("missing sender email address")
	ErrMissingSubject         = errors.New("missing email subject")
	ErrMissingHTMLBody        = errors.New("missing email HTML body")
)

Functions

func HTMLToText

func HTMLToText(htmlContent string) (string, error)

func IsRetryable

func IsRetryable(err error) bool

func IsValidationError

func IsValidationError(err error) bool

func SendMarketing

func SendMarketing(
	ctx context.Context,
	data MarketingData,
	sender MarketingSender,
) error

func SendTransactional

func SendTransactional(
	ctx context.Context,
	data TransactionalData,
	sender TransactionalSender,
) error

Types

type Attachment

type Attachment struct {
	Name        string
	Content     []byte
	ContentType string
	Inline      bool
}

type Log

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

Log logs messages instead of delivering them. It makes production-like local runs and smoke tests possible without an SMTP server or Mailpit, and it is allowed in every environment because nothing leaves the process.

func NewLog

func NewLog(logger *slog.Logger) *Log

NewLog constructs a sender that logs messages. A nil logger uses slog.Default.

func (*Log) SendMarketing

func (sender *Log) SendMarketing(
	ctx context.Context,
	payload MarketingPayload,
) error

func (*Log) SendTransactional

func (sender *Log) SendTransactional(
	ctx context.Context,
	payload TransactionalPayload,
) error

type Mailpit

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

Mailpit sends email through a development Mailpit SMTP server.

func NewMailpit

func NewMailpit(config MailpitConfig) (*Mailpit, error)

NewMailpit constructs a Mailpit client from the supplied configuration.

func (*Mailpit) SendMarketing

func (client *Mailpit) SendMarketing(
	ctx context.Context,
	payload MarketingPayload,
) error

func (*Mailpit) SendTransactional

func (client *Mailpit) SendTransactional(
	ctx context.Context,
	payload TransactionalPayload,
) error

type MailpitConfig

type MailpitConfig struct {
	Host string
	Port string
}

MailpitConfig configures a Mailpit SMTP client. Applications supply host and port.

func (MailpitConfig) Validate

func (config MailpitConfig) Validate() error

Validate verifies Mailpit configuration.

type MarketingData

type MarketingData struct {
	To               []string
	From             string
	ReplyTo          string
	Subject          string
	HTMLBody         string
	TextBody         string
	UnsubscribeURL   string
	UnsubscribeGroup string
	Tags             []string
	Metadata         map[string]string
	TrackOpens       bool
	TrackClicks      bool
}

type MarketingPayload

type MarketingPayload struct {
	To               []string
	From             string
	ReplyTo          string
	Subject          string
	HTMLBody         string
	TextBody         string
	UnsubscribeURL   string
	UnsubscribeGroup string
	Tags             []string
	Metadata         map[string]string
	TrackOpens       bool
	TrackClicks      bool
}

type MarketingSender

type MarketingSender interface {
	SendMarketing(ctx context.Context, payload MarketingPayload) error
}

type PermanentError

type PermanentError struct {
	Err error
}

func (PermanentError) Error

func (err PermanentError) Error() string

func (PermanentError) Unwrap

func (err PermanentError) Unwrap() error

type SMTP

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

SMTP sends email through a production SMTP relay.

func NewSMTP

func NewSMTP(config SMTPConfig) (*SMTP, error)

NewSMTP constructs an SMTP sender from the supplied configuration.

func (*SMTP) SendMarketing

func (sender *SMTP) SendMarketing(
	ctx context.Context,
	payload MarketingPayload,
) error

func (*SMTP) SendTransactional

func (sender *SMTP) SendTransactional(
	ctx context.Context,
	payload TransactionalPayload,
) error

type SMTPConfig

type SMTPConfig struct {
	Host     string
	Port     string
	Username string
	Password string
	TLS      SMTPTLSMode
	Timeout  time.Duration
}

SMTPConfig configures a production SMTP relay.

func (SMTPConfig) Validate

func (config SMTPConfig) Validate() error

Validate verifies SMTP configuration. Username and password must be supplied together, and plaintext authentication is refused outside a local relay.

type SMTPTLSMode

type SMTPTLSMode string

SMTPTLSMode selects how an SMTP connection is encrypted.

const (
	// SMTPTLSStartTLS upgrades a plaintext connection with STARTTLS. It is the
	// default and the right choice for submission on port 587.
	SMTPTLSStartTLS SMTPTLSMode = "starttls"
	// SMTPTLSImplicit dials TLS directly, as submission on port 465 expects.
	SMTPTLSImplicit SMTPTLSMode = "tls"
	// SMTPTLSNone sends plaintext. Only use it for a local relay.
	SMTPTLSNone SMTPTLSMode = "none"
)

type Templates

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

Templates renders the html/text template pairs exported by React Email. Uses text/template on purpose: html/template strips the <!--[if mso]> comments React Email emits for Outlook; HTML placeholders carry an explicit `| html` pipe.

func MustParseTemplates

func MustParseTemplates(fsys fs.FS, dir string) *Templates

MustParseTemplates is ParseTemplates that panics on error. It is for templates committed to the binary with //go:embed, where a parse failure is a build-time bug.

func ParseTemplates

func ParseTemplates(fsys fs.FS, dir string) (*Templates, error)

ParseTemplates parses dir/*.html.tmpl and dir/*.txt.tmpl from fsys. Both template kinds are required: an email without an HTML or a text body is a scaffold mistake, not a render-time surprise.

func (*Templates) HTML

func (t *Templates) HTML(name string, data any) (string, error)

HTML executes "<name>.html.tmpl" with data.

func (*Templates) Text

func (t *Templates) Text(name string, data any) (string, error)

Text executes "<name>.txt.tmpl" with data.

type TemporaryError

type TemporaryError struct {
	Err error
}

func (TemporaryError) Error

func (err TemporaryError) Error() string

func (TemporaryError) Unwrap

func (err TemporaryError) Unwrap() error

type TransactionalData

type TransactionalData struct {
	To          string
	Cc          []string
	Bcc         []string
	From        string
	ReplyTo     string
	Subject     string
	HTMLBody    string
	TextBody    string
	Attachments []Attachment
	Metadata    map[string]string
}

func Compose

func Compose(t Transformer, to, from, subject string) (TransactionalData, error)

Compose renders t into transactional data addressed to a single recipient.

type TransactionalPayload

type TransactionalPayload struct {
	To          string
	Cc          []string
	Bcc         []string
	From        string
	ReplyTo     string
	Subject     string
	HTMLBody    string
	TextBody    string
	Attachments []Attachment
	Metadata    map[string]string
}

type TransactionalSender

type TransactionalSender interface {
	SendTransactional(ctx context.Context, payload TransactionalPayload) error
}

type Transformer

type Transformer interface {
	ToHTML() (string, error)
	ToText() (string, error)
}

Transformer renders an email template to both of its bodies.

type ValidationError

type ValidationError struct {
	Err error
}

func (ValidationError) Error

func (err ValidationError) Error() string

func (ValidationError) Unwrap

func (err ValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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