Documentation ¶
Index ¶
- Constants
- Variables
- type Auth
- type AuthCramMd5
- type AuthExtension
- type AuthPlain
- type AuthUser
- type Conn
- func (c *Conn) EndTX() error
- func (c *Conn) ReadData() (string, error)
- func (c *Conn) ReadLine() (string, error)
- func (c *Conn) ReadSMTP() (string, string, error)
- func (c *Conn) Reset()
- func (c *Conn) StartTX(from *mail.Address) error
- func (c *Conn) WriteEHLO(message string) error
- func (c *Conn) WriteOK() error
- func (c *Conn) WriteSMTP(code int, message string) error
- type Extension
- type Message
- func (m *Message) Attachments() ([]*Part, error)
- func (m *Message) BCC() []*mail.Address
- func (m *Message) FindBody(contentType string) ([]byte, error)
- func (m *Message) HTML() ([]byte, error)
- func (m *Message) ID() string
- func (m *Message) Parts() ([]*Part, error)
- func (m *Message) Plain() ([]byte, error)
- type MessageHandler
- type Part
- type SMTPError
- type Server
- func (s *Server) Address() string
- func (s *Server) Close() error
- func (s *Server) Disable(verbs ...string)
- func (s *Server) Enable(verbs ...string)
- func (s *Server) Extend(verb string, extension Extension) error
- func (s *Server) GetAddressArg(argName string, args string) (*mail.Address, error)
- func (s *Server) Greeting(conn *Conn) string
- func (s *Server) HandleSMTP(conn *Conn) error
- func (s *Server) ListenAndServe(addr string) error
- func (s *Server) SetHelp(message string) error
- func (s *Server) UseAuth(auth Extension)
- func (s *Server) UseTLS(cert, key string) error
- type SimpleAuthFunc
- type SimpleExtension
Constants ¶
const ( DefaultReadTimeout = time.Second * 10 DefaultWriteTimeout = time.Second * 10 DefaultMessageSizeMax = 131072 DefaultSessionCommandsMax = 100 )
Default values
Variables ¶
var ( ErrAlreadyRunning = errors.New("This server is already listening for requests") ErrAuthFailed = SMTPError{535, errors.New("Authentication credentials invalid")} ErrAuthCancelled = SMTPError{501, errors.New("Cancelled")} ErrRequiresTLS = SMTPError{538, errors.New("Encryption required for requested authentication mechanism")} ErrTransaction = SMTPError{501, errors.New("Transaction unsuccessful")} )
Well-defined errors
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
Mechanisms map[string]AuthExtension
}
type AuthCramMd5 ¶
func (*AuthCramMd5) CheckResponse ¶
func (a *AuthCramMd5) CheckResponse(response string, challenge []byte) (AuthUser, bool)
Note: This is currently very weak & requires storing of the user's password in plaintext one good alternative is to do the HMAC manually and expose handlers for pre-processing the password MD5s
func (*AuthCramMd5) Handle ¶
func (a *AuthCramMd5) Handle(conn *Conn, params string) (AuthUser, error)
Handles the negotiation of an AUTH CRAM-MD5 request https://en.wikipedia.org/wiki/CRAM-MD5 http://www.samlogic.net/articles/smtp-commands-reference-auth.htm
type AuthExtension ¶
http://tools.ietf.org/html/rfc4422#section-3.1 https://en.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer
type AuthPlain ¶
type AuthPlain struct {
Auth SimpleAuthFunc
}
type Conn ¶
type Conn struct { // Conn is primarily a wrapper around a net.Conn object net.Conn // Track some mutable for this connection IsTLS bool Errors []error User AuthUser FromAddr *mail.Address ToAddr []*mail.Address // Configuration options MaxSize int64 ReadTimeout time.Duration WriteTimeout time.Duration // contains filtered or unexported fields }
Conn is a wrapper for net.Conn that provides convenience handlers for SMTP requests
func (*Conn) ReadSMTP ¶
ReadSMTP pulls a single SMTP command line (ending in a carriage return + newline)
func (*Conn) WriteEHLO ¶
WriteEHLO writes an EHLO line, see https://tools.ietf.org/html/rfc2821#section-4.1.1.1
type Message ¶
type Message struct { To []*mail.Address From *mail.Address Header mail.Header Subject string RawBody []byte Source []byte // meta info Logger *log.Logger // contains filtered or unexported fields }
Message is a nicely packaged representation of the recieved message
func NewMessage ¶
NewMessage creates a Message from a data blob and a recipients list
func (*Message) Attachments ¶
Attachments returns the list of attachments on this message XXX: this assumes that the only mimetype supporting attachments is multipart/mixed need to review https://en.wikipedia.org/wiki/MIME#Multipart_messages to ensure that is the case
func (*Message) FindBody ¶
FindBody finds the first part of the message with the specified Content-Type
func (*Message) ID ¶
ID returns an identifier for this message, or generates one if none available using the masked string algorithm from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang
type MessageHandler ¶
MessageHandler functions handle application of business logic to the inbound message
type Part ¶
type Part struct { Header textproto.MIMEHeader Body []byte Children []*Part // contains filtered or unexported fields }
Part represents a single part of the message
type SMTPError ¶
SMTPError is an error + SMTP response code
type Server ¶
type Server struct { Name string TLSConfig *tls.Config ServerName string // MaxSize of incoming message objects, zero for no cap otherwise // larger messages are thrown away MaxSize int64 // MaxConn limits the number of concurrent connections being handled MaxConn int // MaxCommands is the maximum number of commands a server will accept // from a single client before terminating the session MaxCommands int // RateLimiter gets called before proceeding through to message handling // TODO: Implement RateLimiter func(*Conn) bool // Handler is the handoff function for messages Handler MessageHandler // Auth is an authentication-handling extension Auth Extension // Extensions is a map of server-specific extensions & overrides, by verb Extensions map[string]Extension // Disabled features Disabled map[string]bool // help message to display in response to a HELP request Help string // Logger to print out status info // TODO: implement better logging with configurable verbosity Logger *log.Logger Verbose bool // Timeout handlers ReadTimeout time.Duration WriteTimeout time.Duration // Ready is a channel that will receive a single `true` when the server has started Ready chan bool // contains filtered or unexported fields }
Server is an RFC2821/5321 compatible SMTP server
func NewServerWithLogger ¶
NewServerWithLogger creates a server with a customer logger
func (*Server) GetAddressArg ¶
GetAddressArg extracts the address value from a supplied SMTP argument for handling MAIL FROM:address@example.com and RCPT TO:address@example.com XXX: don't like this, feels like a hack
func (*Server) Greeting ¶
Greeting is a humanized response to EHLO to precede the list of available commands
func (*Server) HandleSMTP ¶
HandleSMTP handles a single SMTP request
func (*Server) ListenAndServe ¶
ListenAndServe starts listening for SMTP commands at the supplied TCP address