smtptester

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 5 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() *smtp.Server

Standard returns a standard SMTP server listening on :2525

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 *smtp.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 (bkd *Backend) NewSession(_ *smtp.Conn) (smtp.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) AuthPlain

func (s *Session) AuthPlain(username, password string) error

func (*Session) Data

func (s *Session) Data(r io.Reader) error

Data implements the Data interface.

func (*Session) Logout

func (s *Session) Logout() error

Logout implements Logout interface.

func (*Session) Mail

func (s *Session) Mail(from string, opts *smtp.MailOptions) error

Mail implements the Mail interface.

func (*Session) Rcpt

func (s *Session) Rcpt(to string, opts *smtp.RcptOptions) error

Rcpt implements the Rcpt interface.

func (*Session) Reset

func (s *Session) Reset()

Reset implements Reset interface.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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