mail

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0, MIT Imports: 23 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 mail receives SMTP for forwarded addresses and relays each message on to its destinations.

Index

Constants

View Source
const (
	DefaultMaxSize = 25 << 20
)

Variables

This section is empty.

Functions

func IsSRS

func IsSRS(addr string) bool

IsSRS reports whether addr's local part is shaped like a rewritten sender, valid or not.

func IsTemporary

func IsTemporary(err error) bool

func LoadKey

func LoadKey(path string) ([]byte, error)

LoadKey reads the SRS secret at path, creating one on first use.

Types

type Envelope

type Envelope struct {
	From       string
	Recipients []Recipient
	Data       []byte
}

type Error

type Error struct {
	Temporary bool
	Msg       string
}

Error carries an SMTP-shaped outcome: Temporary asks the sender to retry later instead of bouncing.

func (*Error) Error

func (e *Error) Error() string

type Forwarder

type Forwarder struct {
	Hostname string
	SRS      SRS
	Relay    *Relay
	Resolver Resolver
	Dial     func(ctx context.Context, network, addr string) (net.Conn, error)
	Port     string
	Logf     func(format string, args ...any)
}

func (*Forwarder) Forward

func (f *Forwarder) Forward(ctx context.Context, env Envelope) error

Forward delivers env to every destination; once any copy lands it reports success, since a retry would duplicate it for those that already got it.

type Recipient

type Recipient struct {
	Addr         string
	Destinations []string
	Bounce       bool // addressed to a rewritten sender, so it goes back out with a null sender
}

type Relay

type Relay struct {
	Host, Port, User, Pass, From string
}

Relay is an upstream SMTP server that sends on our behalf, for hosts that can't reach port 25 directly.

func RelayFromEnv

func RelayFromEnv() *Relay

type Resolver

type Resolver interface {
	LookupMX(ctx context.Context, name string) ([]*net.MX, error)
	LookupHost(ctx context.Context, host string) ([]string, error)
}

type Rules

type Rules map[string]map[string][]string

Rules maps a domain to its aliases; the "*" alias catches every other address on that domain.

func LoadRules

func LoadRules(path string) (Rules, error)

LoadRules reads the forwarding table; a missing file means nothing is forwarded, while an unreadable one is an error so callers keep their last good copy.

func (Rules) HasDomain

func (r Rules) HasDomain(domain string) bool

func (Rules) Lookup

func (r Rules) Lookup(addr string) ([]string, bool)

Lookup resolves a recipient to its destinations; a +tag suffix on the local part still matches the base alias.

func (Rules) Resolve

func (r Rules) Resolve(addr string) []string

Resolve follows forwards that land on other forwarded addresses, so local chains resolve here instead of looping back through the network.

type SRS

type SRS struct{ Key []byte }

SRS rewrites a forwarded message's sender onto the forwarding domain so SPF keeps passing, while still routing bounces home.

func (SRS) Forward

func (s SRS) Forward(sender, domain string, now time.Time) string

func (SRS) Reverse

func (s SRS) Reverse(addr string, now time.Time) (string, bool)

Reverse decodes an address minted by Forward, rejecting forged or expired ones so it can't be used to relay.

type Server

type Server struct {
	Hostname  string
	Rules     func() Rules
	TLSConfig *tls.Config
	Forwarder *Forwarder
	MaxSize   int64
	Logf      func(format string, args ...any)
	// contains filtered or unexported fields
}

Server accepts mail only for addresses its Rules know, so it can never be used as an open relay.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) Serve

func (s *Server) Serve(ln net.Listener) error

Jump to

Keyboard shortcuts

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