smtptester

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 10 Imported by: 0

README

Go

go-smtptester

Simple SMTP Server for Testing.

How it works

All received mails are saved in a sync.Map with a key:

From+Recipient1+Recipient2

Mails to the same sender and recipients will overwrite a previous received mail, when the recipients slice has the same order as in the mail received before.

Example

See

server_test.go
examples/simple/main.go

for example usage.

Documentation

Overview

Package smtptester implements a simple SMTP server for testing. All received mails are saved in a sync.Map with a key:

From+Recipient1+Recipient2

Mails to the same sender and recipients will overwrite a previous received mail, when the recipients slice has the same order as in the mail received before.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupKey

func LookupKey(f string, r []string) string

LookupKey returns a key of the format:

m.From+m.Recipient_1+m.Recipient_2...

func Standard

func Standard() *server.Server

Standard returns a standard SMTP server listening on :2525

func StandardWithAddress added in v1.0.4

func StandardWithAddress(addr string) *server.Server

StandardWithAddress with address returns a standard SMTP server listenting on addr.

Types

type Backend

type Backend struct {
	Mails sync.Map
}

Backend is the backend for out test server. It contains a sync.Map with all mails received.

func GetBackend

func GetBackend(s *server.Server) *Backend

GetBackend returns the concrete type *Backend from SMTP server.

func NewBackend

func NewBackend() *Backend

NewBackend returns a new Backend with an empty (not nil) Mails map.

func (*Backend) Add

func (b *Backend) Add(m *Mail)

Add adds mail to backends map.

func (*Backend) Load

func (b *Backend) Load(from string, recipients []string) (*Mail, bool)

Load loads mail from 'from' to recipients 'recipients'. The ok result indicates whether value was found in the map.

func (*Backend) NewSession

func (b *Backend) NewSession(ctx context.Context, _ *server.Conn) (context.Context, server.Session, error)

NewSession returns a new Session.

type Mail

type Mail struct {
	From       string
	Recipients []string
	Data       []byte
}

Mail is one mail received by SMTP server.

func (*Mail) LookupKey

func (m *Mail) LookupKey() string

LookupKey call LookupKey for current mail.

type Session

type Session struct {
	// contains filtered or unexported fields
}

A Session is returned after successful login.

func (Session) Auth

func (Session) Auth(_ context.Context, _ string) (sasl.Server, error)

Auth implements the Auth interface.

func (Session) AuthMechanisms

func (Session) AuthMechanisms(_ context.Context) []string

AuthMechanisms implements the AuthMechanisms interface.

func (*Session) Close

func (s *Session) Close(_ context.Context, _ error)

Close implements the Close interface.

func (*Session) Data

func (s *Session) Data(_ context.Context, r func() io.Reader) (string, error)

Data implements the Data interface.

func (Session) Logger

func (Session) Logger(_ context.Context) *slog.Logger

Logger implements the Logger interface.

func (*Session) Mail

func (s *Session) Mail(_ context.Context, from string, _ *smtp.MailOptions) error

Mail implements the Mail interface.

func (*Session) Rcpt

func (s *Session) Rcpt(_ context.Context, to string, _ *smtp.RcptOptions) error

Rcpt implements the Rcpt interface.

func (*Session) Reset

func (s *Session) Reset(ctx context.Context, _ bool) (context.Context, error)

Reset implements Reset interface.

func (Session) STARTTLS

func (Session) STARTTLS(_ context.Context, config *tls.Config) (*tls.Config, error)

STARTTLS implements the STARTTLS interface.

func (Session) Verify added in v1.0.5

func (Session) Verify(_ context.Context, _ string, _ *smtp.VrfyOptions) error

Verify implements the Verify interface.

Directories

Path Synopsis
examples
simple command

Jump to

Keyboard shortcuts

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