server

package
v0.0.0-...-0f5e0da Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 9 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = errors.New("InvalidCredentialsError")

ErrInvalidCredentials denotes incorrect credentials.

Functions

This section is empty.

Types

type AuthBackend

type AuthBackend interface {
	// Login checks whether the credentials of a user are valid.
	// returns ErrInvalidCredentials if credentials not valid.
	Login(state *smtp.State, username string, password string) (User, error)
}

AuthBackend represents a pluggable authentication backend for the MTA

type AuthBackendMemory

type AuthBackendMemory struct {
	Credentials map[string]string
}

AuthBackendMemory is a simple in-memory implementation of AuthBackend for testing purpose.

func NewAuthBackendMemory

func NewAuthBackendMemory(credentials map[string]string) *AuthBackendMemory

NewAuthBackendMemory creates a new in-memory AuthBackend

func (*AuthBackendMemory) Login

func (auth *AuthBackendMemory) Login(state *smtp.State, username string, password string) (User, error)

Login checks whether the credentials of a user are valid

type Blacklist

type Blacklist interface {
	// CheckIp will return true if the IP is blacklisted and false if the IP was not found in a blacklist
	CheckIp(ip string) bool
}

Interface for handling blaclists it is meant to be replaced by your own implementation

type Config

type Config struct {
	Ip          string
	Hostname    string
	Port        uint32
	Blacklist   Blacklist
	DisableAuth bool
	TLSConfig   *tls.Config
}

type DefaultMta

type DefaultMta struct {
	Server *Server
}

Same as the Mta struct but has methods for handling socket connections.

func NewDefault

func NewDefault(c Config, h Handler) *DefaultMta

NewDefault Create a new SMTP server with a socket protocol implementation.

func (*DefaultMta) ListenAndServe

func (s *DefaultMta) ListenAndServe() error

func (*DefaultMta) Stop

func (s *DefaultMta) Stop()

type Handler

type Handler interface {
	Handle(*smtp.State) error
}

Handler is the interface that will be used when a mail was received.

type HandlerFunc

type HandlerFunc func(*smtp.State) error

HandlerFunc is a wrapper to allow normal functions to be used as a handler.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(state *smtp.State) error

type SMTPUser

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

SMTPUser is a quick implementation of the User interface

func (*SMTPUser) Username

func (u *SMTPUser) Username() string

Username returns the username

type Server

type Server struct {

	// The handler to be called when a mail is received.
	MailHandler Handler
	// The config for tls connection. Nil if not supported.
	TlsConfig   *tls.Config
	AuthBackend AuthBackend
	// contains filtered or unexported fields
}

Server Represents an SMTP server

func New

func New(c Config, h Handler) *Server

New Create a new SMTP server that doesn't handle the protocol.

func (*Server) HandleClient

func (s *Server) HandleClient(proto smtp.Protocol)

HandleClient Start communicating with a client

func (*Server) Stop

func (s *Server) Stop()

type User

type User interface {
	Username() string
}

User denotes an authenticated SMTP user.

Jump to

Keyboard shortcuts

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