Documentation
¶
Index ¶
Constants ¶
const ( // ConnGreeting The connection has connected, and is awaiting our first response ConnGreeting = iota // ConnCmd We have responded to the connection's connection and are awaiting a command ConnCmd // ConnData We have received the sender and recipient information ConnData // ConnStartTLS We have agreed with the connection to secure the connection over TLS ConnStartTLS // Server will shut down, connection to shutdown on next command turn ConnShutdown )
const ( Name = "Brevx" Version = "0.0.1" )
const ( // Server has just been created ServerStateNew = iota // Server has just been stopped ServerStateStopped // Server has been started and is running ServerStateRunning // Server could not start due to an error ServerStateStartError )
const CharsetDefault = "default"
const CharsetUtf8 = "SMTPUTF8"
const CommandLineMaxLength = 1024
const CommandVerbMaxLength = 16
Variables ¶
This section is empty.
Functions ¶
func NewSMTPReader ¶
NewSMTPReader setup a new smtpReader with n byte read limit
Types ¶
type ClientState ¶
type ClientState int
ClientState indicates which part of the SMTP transaction a given connection is in.
type Handler ¶
type Handler interface {
// Data processes then saves the mail envelope
// Success should return nil or responses.SuccessMessageQueued
Data(*envelope.Envelope) Response
}
Handler is process received mail. Depending on the implementation, they can store mail in the database, write to a file, check for spam, re-transmit to another Server, etc.
Returning nil will translate to 250 OK Response Returning a non 2xx Response will abort the transaction
func NewHandler ¶
func NewHandler(handler HandlerFunc) Handler
type HandlerFunc ¶
type Middleware ¶
type Middleware func(next HandlerFunc) HandlerFunc
type Response ¶
Response represents a response to an SMTP connection after receiving DATA. The String method should return an SMTP message ready to send back to the connection, for example `250 OK: Message received`.
func NewResponse ¶
type ResponseErr ¶
func WrapResponse ¶
func WrapResponse(res Response, err error) ResponseErr
type SMTPReaderError ¶
type SMTPReaderError string
const LimitError SMTPReaderError = "read limit reached"
func (SMTPReaderError) Error ¶
func (e SMTPReaderError) Error() string
type Server ¶
type Server struct {
Logger *slog.Logger
// Middlewares will be run in the order they are specified before backend is called
// m1 -> m2 -> Handler
// V
// m1 <- m2 <- Handler
Middlewares []Middleware
// Handler will be receiving envelopes after the Data command
Handler Handler
// TLSConfig will be used when TLS is enabled
TLSConfig *tls.Config
// AlwaysOn run this Server as a pure TLS Server, i.e. SMTPS
TLSAlwaysOn bool
// Hostname will be used in the Server's reply to HELO/EHLO. If TLS enabled
// make sure that the Hostname matches the cert. Defaults to os.Hostname()
// Hostname will also be used to fill the 'Host' property when the "RCPT TO" address is
// addressed to just <postmaster>
Hostname string
// Addr is the interface specified in <ip>:<port> - defaults to ":25"
Addr string
// MaxSize is the maximum size of an email that will be accepted for delivery.
// Defaults to 10 Mebibytes
MaxSize int64
// Timeout specifies the connection timeout in seconds. Defaults to 30
// TODO: Implment this
Timeout int
// MaxClients controls how many maximum clients we can handle at once.
// Defaults to defaultMaxClients
// TODO: Implment this
MaxClients int
// XClientOn when using a proxy such as Nginx, XCLIENT command is used to pass the
// original connection's IP address & connection's HELO
XClientOn bool
ProxyOn bool
// MaxRecipients is the maximum number of recipients allowed in a single RCPT command
// Defaults to defaultMaxRecipients = 100
MaxRecipients int
// MaxUnrecognizedCommands is the maximum number of unrecognized commands allowed before the server terminates
// the connection, defaults to defaultMaxUnrecognizedCommands = 5
MaxUnrecognizedCommands int
// contains filtered or unexported fields
}
Server listens for SMTP clients on the port specified in its config
func (*Server) GetActiveClientsCount ¶
func (*Server) ListenAndServe ¶
ListenAndServe begin accepting SMTP clients. Will block unless there is an error or Server.Shutdown() is called
func (*Server) Use ¶
func (s *Server) Use(middleware ...Middleware)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
module
|
|
|
authres
Package authres parses and formats Authentication-Results
|
Package authres parses and formats Authentication-Results |
|
authres/dkim
Package dkim creates and verifies DKIM signatures, as specified in RFC 6376.
|
Package dkim creates and verifies DKIM signatures, as specified in RFC 6376. |
|
authres/dmarc
Package dmarc implements DMARC as specified in RFC 7489.
|
Package dmarc implements DMARC as specified in RFC 7489. |