mailtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 16 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 mailtest is an in-process SMTP server for tests of onemailer and the code that uses it: plain, STARTTLS or implicit TLS, optional AUTH PLAIN, and scripted failures. It listens on 127.0.0.1 only.

srv := mailtest.Start(t, mailtest.Options{Mode: mailtest.StartTLS})
cfg = cfg.WithRootCAs(srv.Roots) // with SMTP_HOST=srv.Host, SMTP_PORT=srv.PortString()
// … send …
got := srv.Messages()

Index

Constants

View Source
const (
	Plain    = "plain"    // no TLS offered
	StartTLS = "starttls" // STARTTLS offered
	Implicit = "tls"      // TLS from the first byte
)

Modes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Mode string
	// CertHost is the name in the certificate; default "localhost" (with the
	// IP 127.0.0.1). Another name makes verification fail.
	CertHost string
	// Username and Password, when set, are required.
	Username, Password string
	// AuthMechs are the AUTH mechanisms offered: "PLAIN" and/or "LOGIN";
	// default PLAIN.
	AuthMechs []string
	// FailData makes the first FailData DATA commands answer 451.
	FailData int
	// RejectRcpt makes RCPT TO answer 550.
	RejectRcpt bool
}

Options configure a server.

type Received

type Received struct {
	From     string
	To       []string
	Data     string
	AuthUser string
	TLS      bool
}

Received is one accepted message.

type Server

type Server struct {
	Host string
	Port int
	// Roots trusts the server's certificate.
	Roots *x509.CertPool
	// contains filtered or unexported fields
}

Server is a running test server.

func Start

func Start(t testing.TB, opts Options) *Server

Start starts a server closed at the end of the test.

func (*Server) Messages

func (s *Server) Messages() []Received

Messages returns the accepted messages so far.

func (*Server) PortString

func (s *Server) PortString() string

PortString returns the port as a string, for an {PREFIX}SMTP_PORT setting.

Jump to

Keyboard shortcuts

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