smtpservermock

package
v0.0.0-...-e334bbe Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownConnectionAddress  = errors.New("unknown address")
	ErrUnknownConnectionSequence = errors.New("unkown connection sequence")
	ErrUnkownMessageSequence     = errors.New("unknown message sequence")
	ErrTimeout                   = errors.New("timeout waiting for clear channel buffer")
)

Functions

This section is empty.

Types

type AuthenticationMethod

type AuthenticationMethod string
const (
	NoAuthentication AuthenticationMethod = ""
	PlainAuth        AuthenticationMethod = "plain"
	CramMd5Auth      AuthenticationMethod = "cram-md5"
)

type Direction

type Direction int
const (
	RequestDir  Direction = 0
	ResponseDir Direction = 1
)

type Message

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

type RawLine

type RawLine struct {
	Direction Direction
	Text      string
}

type Result

type Result struct {
	EntryNo int
	Start   time.Time
	End     time.Time

	Raw      []RawLine
	Messages []Message
}

type Security

type Security string
const (
	NoSecurity  Security = ""
	StartTlsSec Security = "starttls"
	SslTlsSec   Security = "ssl/tls"
)

type SmtpServer

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

func NewSmtpServer

func NewSmtpServer(sec Security, servername, addr, certFile, keyFile string) (*SmtpServer, error)

NewSmtpServer creates a new instance of SmtpServer. Parameters are the type of security (e.g. No security, SSL-TLS, STARTTLS), a servername, the server address (mail.example.com:587), path to PEM encoded public key and path to PEM encoded privat key. Leave the paths empty if no security is applied. An error is returned for an unknown security type or invalid keys

func (*SmtpServer) GetConnectionAddresses

func (s *SmtpServer) GetConnectionAddresses() ([]string, error)

GetConnectionAddresses returns all connection addresses that made a connection to the SMTP server.

func (*SmtpServer) GetResultMessage

func (s *SmtpServer) GetResultMessage(connectionAddress string, connectionSequenceNo int, messageSequenceNo int) (*Message, error)

GetResultMessage returns the mail message received by the SMTP server for a given connection address, connection sequence number and message sequence number. The connection sequence number is usually 1, but can be increased if a subsequent connection would use the same TCP port (which is very unlikely). The message sequence number starts with 1 and is increased by 1 for every new message within the same connection.

func (*SmtpServer) GetResultRawText

func (s *SmtpServer) GetResultRawText(connectionAddress string, connectionSequenceNo int) ([]RawLine, error)

GetResultRawText returns the raw text received by the SMTP server for a given connection address and connection sequence number. The connection sequence number is usually 1, but can be increased if a subsequent connection would use the same TCP port (which is very unlikely).

func (*SmtpServer) ListenAndServe

func (s *SmtpServer) ListenAndServe() error

ListenAndServe starts the SMTP server and begins listening for incoming connections. An error is returned if there was an issue setting up the listener.

func (*SmtpServer) Shutdown

func (s *SmtpServer) Shutdown() error

Shutdown gracefully shuts down the SMTP server It returns an error if there was an issue shutting down the server.

Jump to

Keyboard shortcuts

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