smtpd

package
v1.21.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package smtpd implements a basic SMTP server.

This is a modified version of https://github.com/mhale/smtpd to add optional support for unix sockets.

Package smtpd is the SMTP daemon

Index

Constants

This section is empty.

Variables

View Source
var (
	// Debug `true` enables verbose logging.
	Debug = false
)
View Source
var (
	// DisableReverseDNS allows rDNS to be disabled
	DisableReverseDNS bool
)
View Source
var ErrServerClosed = errors.New("Server has been closed")

ErrServerClosed is the default message when a server closes a connection

Functions

func Listen

func Listen() error

Listen starts the SMTPD server

func ListenAndServe added in v1.21.0

func ListenAndServe(addr string, handler Handler, appName string, hostname string) error

ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.

func ListenAndServeTLS added in v1.21.0

func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler, appName string, hostname string) error

ListenAndServeTLS listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections. Connections may be upgraded to TLS if the client requests it.

func LoginAuth added in v1.6.13

func LoginAuth(username, password string) smtp.Auth

LoginAuth authentication

func Relay added in v1.21.0

func Relay(from string, to []string, msg []byte) error

Relay will connect to a pre-configured SMTP server and send a message to one or more recipients.

func SaveToDatabase added in v1.21.0

func SaveToDatabase(origin net.Addr, from string, to []string, data []byte) (string, error)

SaveToDatabase will attempt to save a message to the database

Types

type AuthHandler added in v1.21.0

type AuthHandler func(remoteAddr net.Addr, mechanism string, username []byte, password []byte, shared []byte) (bool, error)

AuthHandler function called when a login attempt is performed. Returns true if credentials are correct.

type Handler added in v1.21.0

type Handler func(remoteAddr net.Addr, from string, to []string, data []byte) error

Handler function called upon successful receipt of an email. Results in a "250 2.0.0 Ok: queued" response.

type HandlerRcpt added in v1.21.0

type HandlerRcpt func(remoteAddr net.Addr, from string, to string) bool

HandlerRcpt function called on RCPT. Return accept status.

type LogFunc added in v1.21.0

type LogFunc func(remoteIP, verb, line string)

LogFunc is a function capable of logging the client-server communication.

type MsgIDHandler added in v1.21.0

type MsgIDHandler func(remoteAddr net.Addr, from string, to []string, data []byte) (string, error)

MsgIDHandler function called upon successful receipt of an email. Returns a message ID. Results in a "250 2.0.0 Ok: queued as <message-id>" response.

type Server added in v1.21.0

type Server struct {
	Addr              string // TCP address to listen on, defaults to ":25" (all addresses, port 25) if empty
	AppName           string
	AuthHandler       AuthHandler
	AuthMechs         map[string]bool // Override list of allowed authentication mechanisms. Currently supported: LOGIN, PLAIN, CRAM-MD5. Enabling LOGIN and PLAIN will reduce RFC 4954 compliance.
	AuthRequired      bool            // Require authentication for every command except AUTH, EHLO, HELO, NOOP, RSET or QUIT as per RFC 4954. Ignored if AuthHandler is not configured.
	DisableReverseDNS bool            // Disable reverse DNS lookups, enforces "unknown" hostname
	Handler           Handler
	HandlerRcpt       HandlerRcpt
	Hostname          string
	LogRead           LogFunc
	LogWrite          LogFunc
	MaxSize           int // Maximum message size allowed, in bytes
	MaxRecipients     int // Maximum number of recipients, defaults to 100.
	MsgIDHandler      MsgIDHandler
	Timeout           time.Duration
	TLSConfig         *tls.Config
	TLSListener       bool        // Listen for incoming TLS connections only (not recommended as it may reduce compatibility). Ignored if TLS is not configured.
	TLSRequired       bool        // Require TLS for every command except NOOP, EHLO, STARTTLS, or QUIT as per RFC 3207. Ignored if TLS is not configured.
	Protocol          string      // Default tcp, supports unix
	SocketPerm        fs.FileMode // if using Unix socket, socket permissions

	XClientAllowed []string // List of XCLIENT allowed IP addresses
	// contains filtered or unexported fields
}

Server is an SMTP server.

func (*Server) Close added in v1.21.0

func (srv *Server) Close() error

Close - closes the connection without waiting

func (*Server) ConfigureTLS added in v1.21.0

func (srv *Server) ConfigureTLS(certFile string, keyFile string) error

ConfigureTLS creates a TLS configuration from certificate and key files.

func (*Server) ListenAndServe added in v1.21.0

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the either a TCP network address srv.Addr or alternatively a Unix socket. and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":25" is used.

func (*Server) Serve added in v1.21.0

func (srv *Server) Serve(ln net.Listener) error

Serve creates a new SMTP session after a network connection is established.

func (*Server) Shutdown added in v1.21.0

func (srv *Server) Shutdown(ctx context.Context) error

Shutdown - waits for current sessions to complete before closing

Jump to

Keyboard shortcuts

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