Documentation ¶
Overview ¶
Package smtpd implements a basic SMTP server.
Index ¶
- Constants
- Variables
- func ListenAndServe(addr string, handler Handler, appname string, hostname string) error
- func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler, appname string, ...) error
- type AuthHandler
- type Handler
- type HandlerRcpt
- type LogFunc
- type Server
- func (srv *Server) Close() error
- func (srv *Server) ConfigureTLS(certFile string, keyFile string) error
- func (srv *Server) ConfigureTLSWithPassphrase(certFile string, keyFile string, passphrase string) error
- func (srv *Server) ListenAndServe() error
- func (srv *Server) Serve(ln net.Listener) error
- func (srv *Server) Shutdown(ctx context.Context) error
Constants ¶
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorPurple = "\033[35m" ColorCyan = "\033[36m" ColorWhite = "\033[37m" )
Variables ¶
var ( // Debug `true` enables verbose logging. Debug = false )
var ErrServerClosed = errors.New("Server has been closed")
Functions ¶
func ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.
func ListenAndServeTLS ¶
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.
Types ¶
type AuthHandler ¶
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 HandlerRcpt ¶
HandlerRcpt function called on RCPT. Return accept status.
type LogFunc ¶
type LogFunc func(remoteIP, verb, line string)
LogFunc is a function capable of logging the client-server communication.
type Server ¶
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. Handler Handler HandlerRcpt HandlerRcpt Hostname string LogRead LogFunc LogWrite LogFunc MaxSize int // Maximum message size allowed, in bytes 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. // contains filtered or unexported fields }
Server is an SMTP server.
func (*Server) ConfigureTLS ¶
ConfigureTLS creates a TLS configuration from certificate and key files.
func (*Server) ConfigureTLSWithPassphrase ¶
func (srv *Server) ConfigureTLSWithPassphrase( certFile string, keyFile string, passphrase string, ) error
ConfigureTLSWithPassphrase creates a TLS configuration from a certificate, an encrypted key file and the associated passphrase:
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":25" is used.