mailtest

package
v2.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package mailtest runs in-process IMAP and SMTP servers over TLS for tests. Their certificates are self-signed, so clients must skip verification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServerTLSConfig

func ServerTLSConfig(t testing.TB) *tls.Config

ServerTLSConfig returns a TLS configuration with a fresh self-signed certificate for 127.0.0.1 and localhost.

Types

type Delivery

type Delivery struct {
	From string
	To   []string
	Data string
}

Delivery is one message the server accepted.

type IMAP

type IMAP struct {
	Host     string
	Port     string
	Username string
	Password string
	// contains filtered or unexported fields
}

IMAP is an in-process IMAP server with one user.

func StartIMAP

func StartIMAP(t testing.TB, options ...IMAPOption) *IMAP

StartIMAP starts a server with an empty INBOX. It stops when the test ends.

func (*IMAP) Append

func (s *IMAP) Append(t testing.TB, folder, raw string, flags ...imap.Flag) imap.UID

Append stores a raw RFC 5322 message in folder and returns its UID.

func (*IMAP) AppendAt

func (s *IMAP) AppendAt(t testing.TB, folder, raw string, received time.Time, flags ...imap.Flag) imap.UID

AppendAt is Append with the time the server received the message.

func (*IMAP) CreateFolder

func (s *IMAP) CreateFolder(t testing.TB, name string, specialUse ...imap.MailboxAttr)

CreateFolder creates a folder, optionally marked with a special-use attribute such as imap.MailboxAttrArchive.

func (*IMAP) Flags

func (s *IMAP) Flags(t testing.TB, folder string, uid imap.UID) []imap.Flag

Flags returns the flags of the email with uid in folder, or nil when it is not there.

func (*IMAP) HasFlag

func (s *IMAP) HasFlag(t testing.TB, folder string, uid imap.UID, flag imap.Flag) bool

HasFlag reports whether the email with uid in folder carries flag.

func (*IMAP) Subjects

func (s *IMAP) Subjects(t testing.TB, folder string) []string

Subjects lists the subjects in folder, oldest first.

type IMAPOption

type IMAPOption func(*imapConfig)

IMAPOption configures StartIMAP.

func WithSTARTTLS

func WithSTARTTLS() IMAPOption

WithSTARTTLS serves plain connections that upgrade with STARTTLS.

func WithoutMove

func WithoutMove() IMAPOption

WithoutMove advertises neither MOVE nor UIDPLUS.

type SMTP

type SMTP struct {
	Host     string
	Port     string
	Username string
	Password string
	// contains filtered or unexported fields
}

SMTP is an in-process SMTP server over implicit TLS that accepts AUTH LOGIN and AUTH PLAIN for one user and records delivered messages.

func StartSMTP

func StartSMTP(t testing.TB) *SMTP

StartSMTP starts a server that stops when the test ends.

func (*SMTP) Deliveries

func (s *SMTP) Deliveries() []Delivery

Deliveries returns the messages accepted so far.

Jump to

Keyboard shortcuts

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