smtprelay

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package smtprelay delivers emulated SES mail to a real SMTP server using the standard library, asynchronously through a bounded queue.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRecipients is returned when a message has no deliverable recipient.
	ErrNoRecipients = errors.New("smtprelay: no recipients")
	// ErrPlaintextCredentials is returned when AUTH would send credentials unencrypted to a non-local host.
	ErrPlaintextCredentials = errors.New(
		"smtprelay: refusing to send credentials over an unencrypted non-local connection",
	)
)
View Source
var ErrHeaderInjection = errors.New("smtprelay: header value contains a line break")

ErrHeaderInjection is returned when a header value contains CR or LF.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host string
	User string
	Pass string
}

Config is the relay target, mirroring LocalStack's SMTP_HOST/SMTP_USER/SMTP_PASS.

func ConfigFromEnv

func ConfigFromEnv(getenv func(string) string) (Config, bool)

ConfigFromEnv reads SMTP_HOST, SMTP_USER and SMTP_PASS via getenv; ok is false when SMTP_HOST is unset.

type Message

type Message struct {
	Date    time.Time
	ID      string
	From    string
	Subject string
	Text    string
	HTML    string
	// EnvelopeFrom overrides From as the SMTP MAIL FROM (e.g. a SES ReturnPath).
	EnvelopeFrom string
	Raw          []byte
	To           []string
	Cc           []string
	Bcc          []string
	ReplyTo      []string
}

Message is one outbound email. When Raw is set it is sent verbatim and only the envelope fields (EnvelopeFrom, To, Cc, Bcc) are used.

func (Message) Bytes

func (m Message) Bytes() ([]byte, error)

Bytes renders the RFC 5322 message. Bcc recipients never appear in the headers.

type Option

type Option func(*Relay)

Option customises a Relay.

func WithQueueSize

func WithQueueSize(n int) Option

WithQueueSize sets the bounded queue capacity; values below 1 are ignored.

func WithTLSConfig

func WithTLSConfig(c *tls.Config) Option

WithTLSConfig overrides the STARTTLS client configuration (tests use it to trust a self-signed cert).

type Relay

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

Relay queues messages and delivers them from a single worker goroutine.

func New

func New(cfg Config, opts ...Option) *Relay

New starts a relay worker for cfg. Call Close to stop it.

func (*Relay) Close

func (r *Relay) Close()

Close stops the worker, abandoning queued messages, and waits for it to exit. It is idempotent.

func (*Relay) Enqueue

func (r *Relay) Enqueue(m Message) bool

Enqueue adds m to the queue without blocking. It returns false when the queue is full or the relay is closed.

Directories

Path Synopsis
Package smtptest provides a minimal in-process SMTP server for tests.
Package smtptest provides a minimal in-process SMTP server for tests.

Jump to

Keyboard shortcuts

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