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 ¶
- func ServerTLSConfig(t testing.TB) *tls.Config
- type Delivery
- type Gmail
- func (g *Gmail) AddLabels(t testing.TB, id string, labels ...string)
- func (g *Gmail) Append(t testing.TB, raw string, labels ...string) string
- func (g *Gmail) AppendAt(t testing.TB, raw string, received time.Time, labels ...string) string
- func (g *Gmail) CreateLabel(t testing.TB, name string) string
- func (g *Gmail) Delete(t testing.TB, id string)
- func (g *Gmail) DenyScope()
- func (g *Gmail) Labels(t testing.TB, id string) []string
- func (g *Gmail) Sent() []GmailSent
- func (g *Gmail) Subjects(t testing.TB, labelName string) []string
- type GmailSent
- type IMAP
- func (s *IMAP) Append(t testing.TB, folder, raw string, flags ...imap.Flag) imap.UID
- func (s *IMAP) AppendAt(t testing.TB, folder, raw string, received time.Time, flags ...imap.Flag) imap.UID
- func (s *IMAP) CreateFolder(t testing.TB, name string, specialUse ...imap.MailboxAttr)
- func (s *IMAP) Flags(t testing.TB, folder string, uid imap.UID) []imap.Flag
- func (s *IMAP) HasFlag(t testing.TB, folder string, uid imap.UID, flag imap.Flag) bool
- func (s *IMAP) Subjects(t testing.TB, folder string) []string
- type IMAPOption
- type SMTP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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
StartGmail starts an API with an empty mailbox. It stops when the test ends.
func (*Gmail) AddLabels ¶ added in v2.18.2
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
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
AppendAt is Append with the time the mailbox received the message.
func (*Gmail) CreateLabel ¶ added in v2.18.2
CreateLabel creates a user label and returns its ID.
func (*Gmail) Delete ¶ added in v2.18.2
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
Labels returns the names of the labels on the email with id, or nil when it is gone.
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) 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 ¶
CreateFolder creates a folder, optionally marked with a special-use attribute such as imap.MailboxAttrArchive.
func (*IMAP) Flags ¶
Flags returns the flags of the email with uid in folder, or nil when it is not there.
type IMAPOption ¶
type IMAPOption func(*imapConfig)
IMAPOption configures StartIMAP.
func WithSTARTTLS ¶
func WithSTARTTLS() IMAPOption
WithSTARTTLS serves plain connections that upgrade with STARTTLS.
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 (*SMTP) Deliveries ¶
Deliveries returns the messages accepted so far.