smtpd

package
v1.30.5 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package smtpd is the SMTP daemon

Package smtpd implements a basic SMTP server.

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

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

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

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

func LoginAuth(username, password string) smtp.Auth

LoginAuth authentication

func Relay

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

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

SaveToDatabase will attempt to save a message to the database

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 Handler

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

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

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 MsgIDHandler

type MsgIDHandler func(remoteAddr net.Addr, from string, to []string, data []byte, username *string) (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

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
	IgnoreRejectedRecipients bool // Accept emails to rejected recipients with 2xx response but silently drop them
	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

func (srv *Server) Close() error

Close - closes the connection without waiting

func (*Server) ConfigureTLS

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

ConfigureTLS creates a TLS configuration from certificate and key files.

func (*Server) ListenAndServe

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

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

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

func (*Server) Shutdown

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

Shutdown - waits for current sessions to complete before closing

Directories

Path Synopsis
Package chaos is used to simulate Chaos engineering (random failures) in the SMTPD server.
Package chaos is used to simulate Chaos engineering (random failures) in the SMTPD server.

Jump to

Keyboard shortcuts

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