Documentation ¶
Overview ¶
Package smtpd contains source code of the SMTP server of Mailmock.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Responses = map[Resp]Response{ Ready: Response{CodeReady, []string{"<domain> Service ready"}}, Closing: Response{CodeClosing, []string{"<domain> Service closing transmission channel"}}, Success: Response{CodeSuccess, []string{"OK"}}, Data: Response{CodeAskForData, []string{"Start mail input; end with <CRLF>.<CRLF>"}}, NotAvailable: Response{CodeNotAvailable, []string{"<domain> Service not available, closing transmission channel"}}, ShuttingDown: Response{CodeNotAvailable, []string{"<domain> Service shutting down and closing transmission channel"}}, SessionTimeout: Response{CodeNotAvailable, []string{"Your session timed out due to inactivity"}}, Abort: Response{CodeAbort, []string{"Requested action aborted: error in processing"}}, CommandUnrecognized: Response{CodeCommandUnrecognized, []string{"Syntax error, command unrecognized"}}, ParameterSyntax: Response{CodeParameterSyntax, []string{"Syntax error in parameters or arguments"}}, CommandNotImplemented: Response{CodeNotImplemented, []string{"Command not implemented"}}, BadSequence: Response{CodeBadSequence, []string{"Bad sequence of commands"}}, NoValidRecipients: Response{CodeTransactionFailed, []string{"No valid recipients"}}, Misconfiguration: Response{CodeTransactionFailed, []string{"Server is unable to reply to the requested action"}}, Help: Response{CodeHelp, []string{""}}, Status: Response{CodeStatus, []string{""}}, Extensions: Response{CodeSuccess, []string{"<domain>", "HELP"}}, }
Responses returned by the SMTP server
Functions ¶
func ParseCommand ¶
ParseCommand parses a SMTP command, returns appropriate response if the command is malformed If the command is well formed, returned response is nil.
Types ¶
type Code ¶
type Code uint16
Code is an alias for the type uint16
const ( CodeStatus Code = 211 // System status, or system help reply CodeHelp Code = 214 // Help message (Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful only to the human user) CodeReady Code = 220 // <domain> Service ready CodeClosing Code = 221 // <domain> Service closing transmission channel CodeSuccess Code = 250 // Requested mail action okay, completed CodeUserNotLocalTemp Code = 251 // User not local; will forward to <forward-path> CodeCannotVerify Code = 252 // Cannot VRFY user, but will accept message and attempt delivery CodeAskForData Code = 354 // Start mail input; end with <CRLF>.<CRLF> CodeNotAvailable Code = 421 // <domain> Service not available, closing transmission channel CodeAbort Code = 451 // Requested action aborted: local error in processing CodeInsufficientStorageTemp Code = 452 // Requested action not taken: insufficient system storage CodeUnableAccomodateParam Code = 455 // Server unable to accommodate parameters CodeCommandUnrecognized Code = 500 // Syntax error, command unrecognized CodeParameterSyntax Code = 501 // Syntax error in parameters or arguments CodeNotImplemented Code = 502 // Command not implemented CodeBadSequence Code = 503 // Bad sequence of commands CodeParameterNotImplemented Code = 504 // Command parameter not implemented CodeUserNotLocalPerm Code = 551 // User not local; please try <forward-path> CodeInsufficientStoragePerm Code = 552 // Requested mail action aborted: exceeded storage allocation CodeMailboxNotAllowed Code = 553 // Requested action not taken: mailbox name not allowed (e.g., mailbox syntax incorrect) CodeTransactionFailed Code = 554 // Transaction failed CodeMailFromRcptToParam Code = 555 // MAIL FROM/RCPT TO parameters not recognized or not implemented )
SMTP reply codes as defined by RFC 5321, 4.2.3
type Command ¶
type Command struct { FullCmd string Name string PositionalArgs []string NamedArgs map[string]string }
Command is a parsed SMTP command.
type Envelope ¶
Envelope contains the sender address (originator or return-path) and the recipients address (or forward-paths).
type Resp ¶
type Resp uint16
Resp is an alias for the type uint16
const ( Ready Resp = iota // First response Closing // Service closing Success // Requested action completed Abort // Requested action aborted Data // Ask for data input NotAvailable // Service is not available ShuttingDown // Service is shutting down SessionTimeout // Session timeout CommandUnrecognized // Syntax error, command unrecognized ParameterSyntax // Syntax error in parameters or arguments CommandNotImplemented // Command not implemented BadSequence // Bad sequence of commands NoValidRecipients // Transaction failed : no valid recipients Help // Help response Status // Server status Misconfiguration // Unable to reply because of misconfiguration Extensions // Reply to EHLO with supported extensions )
Responses
type Response ¶
Response holds a 3 digit code and a messsage.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is holding the SMTP server properties.
func NewServer ¶
func NewServer(name string, host string, port string, th *TransactionHandler, logger log.Logger) *Server
NewServer creates a SMTP server.
func (*Server) ListenAndServe ¶
ListenAndServe starts listening for clients connection and serves SMTP commands.
type Session ¶
type Session struct { State SessionState `json:"state"` Client string `json:"client"` Tr *Transaction `json:"transaction"` Extended bool // contains filtered or unexported fields }
Session represents a SMTP session of a client.
func NewSession ¶
NewSession return a new Session.
type SessionState ¶
type SessionState string
SessionState is the state of a Session.
const ( SSInitiated SessionState = "initiated" SSReady SessionState = "ready" SSBusy SessionState = "busy" SSClosed SessionState = "closed" )
Session States
type Transaction ¶
type Transaction struct { Mail Mail `json:"mail"` State TransactionState `json:"state"` History []string `json:"history"` }
Transaction represents either a successful, ongoing or aborted SMTP transaction.
func NewTransaction ¶
func NewTransaction() *Transaction
NewTransaction creates a new SMTP transaction with initial state set to TSInitiated.
func (*Transaction) Abort ¶
func (tr *Transaction) Abort() error
Abort sets transaction's state to TSAborted.
func (*Transaction) Data ¶
func (tr *Transaction) Data(data []string) (*Response, error)
Data sets full data, this method can only be user during TSData phase.
func (*Transaction) Process ¶
func (tr *Transaction) Process(cmd *Command) (*Response, error)
Process reads the given command, updates the transaction and returns appropriate response.
func (Transaction) String ¶
func (tr Transaction) String() string
type TransactionHandler ¶
type TransactionHandler func(*Transaction)
TransactionHandler will be called each time a transaction reach TSCompleted or TSAborted status.
type TransactionState ¶
type TransactionState string
TransactionState is the state of a Transaction.
const ( TSInitiated TransactionState = "initiated" // no command was received yet TSInProgress TransactionState = "in progress" // sender address is set, and recipients are being filled TSData TransactionState = "reading data" // sender and recipients are set, waiting for data to complete TSCompleted TransactionState = "completed" // data is received, the transaction is successfully completed TSAborted TransactionState = "aborted" // the transaction is not complete )
Transaction States