postmark

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package postmark sends email through Postmark.

Choosing it commits a deployment to a Postmark server token, which is per-server rather than per-account and therefore selects which stream the mail is billed and reported against. Config.BaseURL overrides the API host, which is what points the package at an httptest server.

The context does not reach the wire

This is the one emailer here whose vendor client takes no context. SendEmail accepts one, and uses it for the span and for the metrics it records, but the HTTP call underneath is issued without it: cancelling the context or letting its deadline lapse does not abort a send in flight. What bounds a send is the timeout on the *http.Client the caller supplied. Every other provider in this family passes the context through to the request.

What one send is

SendEmail delivers one HTML message to one recipient and returns when Postmark has answered, recording the returned message ID on the span. It is synchronous and does not retry; a failed send scores the circuit breaker, and while that breaker is open every call returns circuitbreaking.ErrCircuitBroken. Addresses are rendered through email.FormatAddress, which quotes the display name so a comma in it cannot inject recipients.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNilConfig indicates a nil config was provided.
	ErrNilConfig = platformerrors.New("postmark config is nil")
	// ErrEmptyServerToken indicates an empty server token was provided.
	ErrEmptyServerToken = platformerrors.New("empty Postmark server token")
	// ErrNilHTTPClient indicates a nil HTTP client was provided.
	ErrNilHTTPClient = platformerrors.New("nil postmark HTTP client")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	ServerToken string `env:"SERVER_TOKEN" json:"serverToken,omitempty" yaml:"serverToken,omitempty"`
	// BaseURL overrides the API base URL (e.g. for testing with httptest).
	BaseURL string `env:"BASE_URL" json:"baseURL,omitempty" yaml:"baseURL,omitempty"`
}

Config configures Postmark to send email.

func (*Config) ValidateWithContext

func (s *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates a Config struct.

type Emailer

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

Emailer uses Postmark to send email.

func NewPostmarkEmailer

func NewPostmarkEmailer(cfg *Config, client *http.Client, circuitBreaker circuitbreaking.CircuitBreaker, opts ...Option) (*Emailer, error)

NewPostmarkEmailer returns a new Postmark-backed Emailer.

func (*Emailer) SendEmail

func (e *Emailer) SendEmail(ctx context.Context, details *email.OutboundEmailMessage) error

SendEmail sends an email.

type Option

type Option func(*options)

Option configures the Emailer this package constructs. The zero configuration works: an absent logger logs nowhere, an absent tracer provider traces nowhere, and an absent metrics provider records nothing.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger.

func WithMetricsProvider

func WithMetricsProvider(metricsProvider metrics.Provider) Option

WithMetricsProvider attaches a metrics provider.

func WithTracerProvider

func WithTracerProvider(tracerProvider tracing.Provider) Option

WithTracerProvider attaches a tracer provider, enabling spans on every send.

Jump to

Keyboard shortcuts

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