evsmtp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrPrefix        = "evsmtp: "
	ErrConnectionMsg = ErrPrefix + "connection was not created"
	DefaultEmail     = "user@example.org"
	DefaultSMTPPort  = 25
	DefaultHelloName = "localhost"
)

Configuration constants

View Source
const (
	RandomRCPTStage = CloseStage + 1
	ConnectionStage = RandomRCPTStage + 1
)

Constants of stages

View Source
const (
	// DefaultTimeoutConnection is timeout for connection
	DefaultTimeoutConnection = 5 * time.Second
	// DefaultTimeoutResponse is timeout for communication with smtp server
	DefaultTimeoutResponse = 5 * time.Second
)
View Source
const TCPConnection = "tcp"

TCPConnection is tcp name

Variables

View Source
var (
	// ErrConnection is error of connection
	ErrConnection = NewError(ConnectionStage, errors.New(ErrConnectionMsg))
	// DefaultFromEmail is address, used as default From email
	DefaultFromEmail = evmail.FromString(DefaultEmail)
)
View Source
var DirectDialVar = DirectDial
View Source
var H12ioDialVar = socks.Dial
View Source
var SmtpNewClientVar = smtp.NewClient

Functions

func DefaultRandomCacheKeyGetter

func DefaultRandomCacheKeyGetter(email evmail.Address) interface{}

DefaultRandomCacheKeyGetter generates of cache key for RandomRCPT

func DirectDial

func DirectDial(ctx context.Context, addr, proxyURL string) (smtpclient.SMTPClient, error)

DirectDial generates smtpclient.SMTPClient (smtp.Client)

func ExtID

func ExtID() int8

ExtID returns register extent id, used for msgpack.RegisterExt

func H12IODial

func H12IODial(ctx context.Context, addr, proxyURL string) (smtpclient.SMTPClient, error)

H12IODial generates smtpclient.SMTPClient (smtp.Client) with proxy in socks.Dial

func SetExtID

func SetExtID(rExt int8)

SetExtID sets register extent id, used for msgpack.RegisterExt

Types

type ARandomRCPT

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

ARandomRCPT is abstract realization of RandomRCPT

func (*ARandomRCPT) Call

func (a *ARandomRCPT) Call(sm SendMail, email evmail.Address) []error

Call is calling of RandomRCPTFunc

func (*ARandomRCPT) Get

func (a *ARandomRCPT) Get() RandomRCPTFunc

func (*ARandomRCPT) Set

func (a *ARandomRCPT) Set(fn RandomRCPTFunc)

type ASMTPError

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

ASMTPError isa abstract struct for Checker errors

func (*ASMTPError) DecodeMsgpack

func (a *ASMTPError) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack implements decoder for msgpack

func (*ASMTPError) EncodeMsgpack

func (a *ASMTPError) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack implements encoder for msgpack

func (*ASMTPError) Error

func (a *ASMTPError) Error() string

func (*ASMTPError) Stage

func (a *ASMTPError) Stage() SendMailStage

Stage returns stage of error

func (*ASMTPError) Unwrap

func (a *ASMTPError) Unwrap() error

type AliasError

type AliasError error

AliasError is alias to fix msgpack

func ErrorsToEVSMTPErrors

func ErrorsToEVSMTPErrors(errs []error) (Errs []AliasError)

ErrorsToEVSMTPErrors converts []error to []AliasError It is used like fix of msgpack problems https://github.com/vmihailenco/msgpack/issues/294

type Checker

type Checker interface {
	Validate(mxs MXs, input Input) []error
}

Checker is SMTP validation

func NewChecker

func NewChecker(dto CheckerDTO) Checker

NewChecker instantiates Checker

func NewCheckerCacheRandomRCPT

func NewCheckerCacheRandomRCPT(checker CheckerWithRandomRCPT, cache evcache.Interface, getKey RandomCacheKeyGetter) Checker

NewCheckerCacheRandomRCPT creates Checker with caching of RandomRCPT calling

type CheckerCacheRandomRCPTStruct

type CheckerCacheRandomRCPTStruct struct {
	CheckerWithRandomRCPT
	RandomRCPTOpt RandomRCPT
	Cache         evcache.Interface
	GetKey        RandomCacheKeyGetter
}

func (CheckerCacheRandomRCPTStruct) RandomRCPT

func (c CheckerCacheRandomRCPTStruct) RandomRCPT(sm SendMail, email evmail.Address) (errs []error)

type CheckerDTO

type CheckerDTO struct {
	SendMailFactory SendMailDialerFactory
	RandomEmail     RandomEmail
	Options         Options
}

CheckerDTO is DTO for NewChecker

type CheckerStruct

type CheckerStruct struct {
	RandomRCPT
	SendMailFactory SendMailDialerFactory
	Auth            smtp.Auth
	RandomEmail     RandomEmail
	Options         Options
}

CheckerStruct some SMTP server send additional message and we should read it 2.1.5 for OK message

func (CheckerStruct) Validate

func (c CheckerStruct) Validate(mxs MXs, input Input) (errs []error)

type CheckerWithRandomRCPT

type CheckerWithRandomRCPT interface {
	Checker
	RandomRCPT
}

CheckerWithRandomRCPT is used for caching of RandomRCPT

type DefaultError

type DefaultError struct {
	ASMTPError
}

DefaultError is default error

type DialFunc

type DialFunc func(ctx context.Context, addr, proxyURL string) (smtpclient.SMTPClient, error)

DialFunc is function type to create smtpclient.SMTPClient

type Error

type Error interface {
	error
	Stage() SendMailStage
	Unwrap() error
}

Error is interface of Checker errors

func NewError

func NewError(stage SendMailStage, err error) Error

NewError is constructor for DefaultError

type FuncLookupMX

type FuncLookupMX func(domain string) (MXs, error)

FuncLookupMX returns MXs

type Input

type Input interface {
	Email() evmail.Address
	Options
}

Input describes data for Checker

func NewInput

func NewInput(email evmail.Address, opts Options) Input

NewInput instantiates Input

type InputStruct

type InputStruct struct {
	EmailAddress evmail.Address
	Options
}

func (*InputStruct) Email

func (i *InputStruct) Email() evmail.Address

type MXs

type MXs = []*net.MX

MXs is short alias for []*net.MX

func LookupMX

func LookupMX(domain string) (MXs, error)

LookupMX is default realization for looking net.MX

type Options

type Options interface {
	EmailFrom() evmail.Address
	HelloName() string
	Proxy() string
	TimeoutConnection() time.Duration
	TimeoutResponse() time.Duration
	Port() int
}

Options describes smtp options

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns options with default values

func EmptyOptions

func EmptyOptions() Options

EmptyOptions returns empty options to avoid rewriting of default values

func NewOptions

func NewOptions(dto OptionsDTO) Options

NewOptions instantiates Options

type OptionsDTO

type OptionsDTO struct {
	EmailFrom   evmail.Address
	HelloName   string
	Proxy       string
	TimeoutCon  time.Duration
	TimeoutResp time.Duration
	Port        int
}

OptionsDTO is dto for NewOptions

type OptionsStruct

type OptionsStruct struct {
	EmailFromOption   evmail.Address
	HelloNameOption   string
	ProxyOption       string
	TimeoutConOption  time.Duration
	TimeoutRespOption time.Duration
	PortOption        int
}

func (*OptionsStruct) EmailFrom

func (i *OptionsStruct) EmailFrom() evmail.Address

func (*OptionsStruct) HelloName

func (i *OptionsStruct) HelloName() string

func (*OptionsStruct) Port

func (i *OptionsStruct) Port() int

func (*OptionsStruct) Proxy

func (i *OptionsStruct) Proxy() string

func (*OptionsStruct) TimeoutConnection

func (i *OptionsStruct) TimeoutConnection() time.Duration

func (*OptionsStruct) TimeoutResponse

func (i *OptionsStruct) TimeoutResponse() time.Duration

type RandomCacheKeyGetter

type RandomCacheKeyGetter func(email evmail.Address) interface{}

RandomCacheKeyGetter is type of function to Get cache key

type RandomEmail

type RandomEmail func(domain string) (evmail.Address, error)

RandomEmail is function type to generate random email for checking of Catching All emails by RCPTs

type RandomRCPT

type RandomRCPT interface {
	Call(sm SendMail, email evmail.Address) []error
	Set(fn RandomRCPTFunc)
	Get() RandomRCPTFunc
}

RandomRCPT Need to realize of is-a relation (inheritance)

type RandomRCPTFunc

type RandomRCPTFunc func(sm SendMail, email evmail.Address) (errs []error)

RandomRCPTFunc is function for checking of Catching All

type SafeSendMailStage

type SafeSendMailStage struct {
	SendMailStage
	// contains filtered or unexported fields
}

SafeSendMailStage is thread safe SendMailStage

func (*SafeSendMailStage) Get

Get returns stage

func (*SafeSendMailStage) Set

func (s *SafeSendMailStage) Set(val SendMailStage)

Set sets stage

type SendMail

type SendMail interface {
	Client() smtpclient.SMTPClient
	Hello(helloName string) error
	Auth(a smtp.Auth) error
	Mail(from string) error
	RCPTs(addrs []string) map[string]error
	Data() (io.WriteCloser, error)
	Write(w io.WriteCloser, msg []byte) error
	Quit() error
	Close() error
}

SendMail is interface of custom realization as smtp.SendMail

func NewSendMail

func NewSendMail(client smtpclient.SMTPClient, tlsConfig *tls.Config) SendMail

NewSendMail instantiates SendMail

type SendMailDialerFactory

type SendMailDialerFactory func(ctx context.Context, host string, opts Options) (SendMail, error)

SendMailDialerFactory is factory for SendMail with dialing

func NewSendMailCustom

func NewSendMailCustom(dialFunc DialFunc, tlsConfig *tls.Config, factory SendMailFactory) SendMailDialerFactory

NewSendMailCustom creates SendMailFactory with dialing and customization calling of SendMailFactory

func NewSendMailFactory

func NewSendMailFactory(dialFunc DialFunc, tlsConfig *tls.Config) SendMailDialerFactory

NewSendMailFactory creates SendMailDialerFactory

type SendMailFactory

type SendMailFactory func(client smtpclient.SMTPClient, tlsConfig *tls.Config) SendMail

SendMailFactory is factory for SendMail

type SendMailStage

type SendMailStage uint8

SendMailStage is stage type of SendMail

const (
	ClientStage SendMailStage = iota + 1
	HelloStage
	AuthStage
	MailStage
	RCPTsStage
	QuitStage
	CloseStage
)

Constants of stages

type SendMailStruct

type SendMailStruct struct {
	SMTPClient smtpclient.SMTPClient
	TLSConfig  *tls.Config
}

func (*SendMailStruct) Auth

func (s *SendMailStruct) Auth(a smtp.Auth) error

func (*SendMailStruct) Client

func (s *SendMailStruct) Client() smtpclient.SMTPClient

func (*SendMailStruct) Close

func (s *SendMailStruct) Close() error

func (*SendMailStruct) Data

func (s *SendMailStruct) Data() (io.WriteCloser, error)

func (*SendMailStruct) Hello

func (s *SendMailStruct) Hello(helloName string) error

func (*SendMailStruct) Mail

func (s *SendMailStruct) Mail(from string) error

func (*SendMailStruct) Quit

func (s *SendMailStruct) Quit() error

func (*SendMailStruct) RCPTs

func (s *SendMailStruct) RCPTs(addrs []string) map[string]error

func (*SendMailStruct) Write

func (s *SendMailStruct) Write(w io.WriteCloser, msg []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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