mailtest

package
v2.18.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: GPL-3.0 Imports: 33 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 Gmail added in v2.18.2

type Gmail struct {
	// URL is the API endpoint.
	URL string
	// Token is the access token every request must carry.
	Token string
	// contains filtered or unexported fields
}

Gmail is an in-process Gmail API serving one mailbox. It answers the calls the mailbox package makes and fails the test on any other request.

func StartGmail added in v2.18.2

func StartGmail(t testing.TB) *Gmail

StartGmail starts an API with an empty mailbox. It stops when the test ends.

func (*Gmail) AddLabels added in v2.18.2

func (g *Gmail) AddLabels(t testing.TB, id string, labels ...string)

AddLabels puts labels, by name, on the email with id, as a person or a filter in Gmail does.

func (*Gmail) Append added in v2.18.2

func (g *Gmail) Append(t testing.TB, raw string, labels ...string) string

Append stores a raw RFC 5322 message under the labels, by name, and returns its message ID. It counts as received now.

func (*Gmail) AppendAt added in v2.18.2

func (g *Gmail) AppendAt(t testing.TB, raw string, received time.Time, labels ...string) string

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

func (*Gmail) CreateLabel added in v2.18.2

func (g *Gmail) CreateLabel(t testing.TB, name string) string

CreateLabel creates a user label and returns its ID.

func (*Gmail) Delete added in v2.18.2

func (g *Gmail) Delete(t testing.TB, id string)

Delete removes the email with id for good, as emptying the trash does.

func (*Gmail) DenyScope added in v2.18.2

func (g *Gmail) DenyScope()

DenyScope answers every later request as Gmail does for a token that does not grant Gmail access.

func (*Gmail) Labels added in v2.18.2

func (g *Gmail) Labels(t testing.TB, id string) []string

Labels returns the names of the labels on the email with id, or nil when it is gone.

func (*Gmail) Sent added in v2.18.2

func (g *Gmail) Sent() []GmailSent

Sent returns the messages sent so far.

func (*Gmail) Subjects added in v2.18.2

func (g *Gmail) Subjects(t testing.TB, labelName string) []string

Subjects lists the subjects of the email under the label, by name, oldest first. As in Gmail, a label other than SPAM or TRASH leaves out email in either.

type GmailSent added in v2.18.2

type GmailSent struct {
	Raw      string
	ThreadID string
}

GmailSent is a message the API sent.

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