smtpserver

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecurityPass string = "pass"
	SecurityFail string = "fail"
)

Variables

View Source
var (
	ErrHashFail           = errors.New("error while hashing password")
	ErrInvalidDestination = errors.New("invalid destination")
	ErrParsingError       = errors.New("parsing error")
	ErrDomainMisalignment = errors.New("domains not aligned")
	ErrMaxSizeExceeded    = errors.New("maximum message size exceeded")
	ErrValidationError    = errors.New("validation failed")
	ErrMissingDependency  = errors.New("missing dependency")
)
View Source
var (
	ErrSMTPInvalidDestination = &smtp.SMTPError{
		Code:         552,
		EnhancedCode: smtp.EnhancedCode{5, 3, 4},
		Message:      "Invalid destination",
	}

	ErrSMTPServerError = &smtp.SMTPError{
		Code:         552,
		EnhancedCode: smtp.EnhancedCode{5, 3, 4},
		Message:      "Server error",
	}
)

TODO research valid SMTP codes.

Functions

func GetTLSConfig

func GetTLSConfig(c *TLSConfig) (*tls.Config, error)

func LimitedRead

func LimitedRead(r io.Reader, size int64) ([]byte, error)

LimitedRead validates a mail message is no more than 'size' bytes, and returns a new io.Reader containing a copy of the original bytes.

func NewBackend added in v0.1.2

func NewBackend(ss smtp.Backend, tc *tls.Config, port, maxSize int, hostname string) *smtp.Server

Types

type Config added in v0.1.2

type Config struct {
	Hostname string             `json:"hostname,omitempty"`
	Port     int                `json:"port,omitempty"`
	MaxSize  string             `json:"max_size,omitempty"`
	Outbound *smtpclient.Config `json:"outbound,omitempty"`
	TLS      *TLSConfig         `json:"tls,omitempty"`
}

func (*Config) Validate added in v0.1.2

func (c *Config) Validate() error

type DKIMChecker added in v0.1.2

type DKIMChecker interface {
	GetStatus(raw []byte) (dkim.Status, error)
	ValidateAlignment(raw []byte, from string) (bool, error)
}

type SMTPClient added in v0.1.2

type SMTPClient interface {
	SendMail(*letterbox.ForwardingMessage) error
}

type SMTPService

type SMTPService struct {
	Config           Config
	Server           *smtp.Server
	TLSServer        *smtp.Server
	GlobalSMTPClient SMTPClient
	MaxSize          int64

	// Service Dependencies
	DB     letterbox.Datastore
	Logger *logger.Logger
	DKIM   DKIMChecker
	SPF    SPFChecker
}

func (*SMTPService) AnonymousLogin added in v0.1.2

func (ss *SMTPService) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error)

AnonymousLogin requires clients to authenticate using SMTP AUTH before sending emails.

func (*SMTPService) Login added in v0.1.2

func (ss *SMTPService) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error)

Login handles a login command with username and password.

func (*SMTPService) Name

func (ss *SMTPService) Name() string

func (*SMTPService) Start

func (ss *SMTPService) Start() error

func (*SMTPService) Stop

func (ss *SMTPService) Stop() error

type SPFChecker added in v0.1.2

type SPFChecker interface {
	GetStatus(remoteIP net.IP, helo, fromHeader string) (spf.Status, error)
	ValidateAlignment(from, fromHeader string) (bool, error)
}

type Session added in v0.1.2

type Session struct {
	Service    *SMTPService
	DKIM       DKIMChecker
	SPF        SPFChecker
	Log        letterbox.Logger
	RemoteAddr net.Addr
	Helo       string
	From       string
	To         string
	Mailbox    *letterbox.Mailbox
}

func (*Session) Data added in v0.1.2

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

func (*Session) Logout added in v0.1.2

func (s *Session) Logout() error

func (*Session) Mail added in v0.1.2

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

func (*Session) Rcpt added in v0.1.2

func (s *Session) Rcpt(to string) error

func (*Session) Reset added in v0.1.2

func (s *Session) Reset()

type TLSConfig added in v0.1.2

type TLSConfig struct {
	// The certificate string
	Cert string `json:"cert,omitempty"`

	// The (unencrypted) private key string
	Key string `json:"key,omitempty"`

	// The path to the file containing the certificate
	CertFile string `json:"cert_file,omitempty"`

	// The path to the file containing the (unencrypted) private key
	KeyFile string `json:"key_file,omitempty"`

	// The port to use for the TLS-only SMTPS server
	// This server is wrapped with TLS, and doesn't use the STARTTLS function
	// See RFC8314
	Port int `json:"port,omitempty"`
}

func (*TLSConfig) Validate added in v0.1.2

func (c *TLSConfig) Validate() error

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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