go-smtpsrv: github.com/alash3al/go-smtpsrv Index | Files

package smtpsrv

import "github.com/alash3al/go-smtpsrv"

Index

Package Files

helpers.go processors.go request.go server.go vars.go

Variables

var (
    // ErrorRequestedActionAbortedLocalError ..
    ErrorRequestedActionAbortedLocalError = errors.New("Requested action aborted: local error in processing")
    // ErrorTransactionFailed ..
    ErrorTransactionFailed = errors.New("Transaction failed")
    // ErrorServiceNotAvailable ..
    ErrorServiceNotAvailable = errors.New("Service not available, closing transmission channel")
    // ErrorRequestedActionAbortedExceededStorage ..
    ErrorRequestedActionAbortedExceededStorage = errors.New("Requested mail action aborted: exceeded storage allocation")
)
var (
    // DefaultProcessors holds processor functions
    DefaultProcessors = map[string]Processor{
        "EHLO":     ehloProcessor,
        "HELO":     ehloProcessor,
        "STARTTLS": starttlsProcessor,
        "AUTH":     authProcessor,
        "MAIL":     mailProcessor,
        "RCPT":     rcptProcessor,
        "DATA":     dataProcessor,
        "RSET":     rsetProcessor,
        "VRFY":     vrfyProcessor,
        "EXPN":     expnProcessor,
        "HELP":     helpProcessor,
        "NOOP":     noopProcessor,
        "QUIT":     quitProcessor,
    }
)

func CanonicalizeEmail Uses

func CanonicalizeEmail(local string) string

CanonicalizeEmail format the specified email address I'm following googles example here. Basically all '.' dont matter in the local portion. Also you can append a '+' section to the end of your email and it will still route to you. This allows categorization of emails when they are given out. The muxer will canonicalize incoming email addresses to route them to a handler. The handler will still see the original email in the to portion.

func LimitDataSize Uses

func LimitDataSize(r io.Reader, s int64) io.Reader

LimitDataSize Limit the incoming data size of the DATA command

func ListenAndServe Uses

func ListenAndServe(addr string, handler Handler) error

ListenAndServe start listening on the specified addr using the specified handler

func ListenAndServeTLS Uses

func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error

ListenAndServeTLS start listening on the specified addr using the specified handler and tls configs

func SplitAddress Uses

func SplitAddress(address string) (string, string, error)

SplitAddress split the email@addre.ss to <user>@<domain>

type Handler Uses

type Handler func(req *Request) error

Handler is a 'net/http' like handler but for mails

type Processor Uses

type Processor func(req *Request) error

Processor is a SMTP command processor

type Request Uses

type Request struct {
    // the currently running server
    Server *Server

    // the underlying socket for currently connected client
    Conn net.Conn

    // an instance of go stdlib for handling the above Conn as a text-porotocol
    TextProto *textproto.Conn

    // TLS related info
    TLSState *tls.ConnectionState

    // a shortcut for Conn.RemoteAddr()
    RemoteAddr string

    // contains the hostname of the currently connected client during the EHLO/HELO command
    HelloHost string

    // whether EHLO/HELO called or not
    HelloRecieved bool

    // the login username used for login, empty means that this is an anonymous attempt
    AuthUser string

    // the user that sends the mail
    From string

    // the rctps!
    To  []string

    // the raw DATA section
    Message io.Reader

    // whether the client called QUIT or not
    QuitSent bool

    // the spf checking result
    SPFResult spf.Result

    // whether the FROM mail is mailable or not
    Mailable bool

    // the currently processing line
    Line []string
}

Request is the incoming connection meta-data

func NewRequest Uses

func NewRequest(conn net.Conn, srv *Server) (req *Request, err error)

NewRequest creates a new instance of the Request struct

func (*Request) Process Uses

func (req *Request) Process() error

Process start parsing and processing the current command-line

func (*Request) Reset Uses

func (req *Request) Reset()

Reset resets to the defaults

func (*Request) Serve Uses

func (req *Request) Serve()

Serve start accepting incoming connections

type Server Uses

type Server struct {
    // The name of the server used while greeting
    Name string

    // The address to listen on
    Addr string

    // The default inbox handler
    Handler Handler

    // If a tls config is set then this server will broadcast support
    // for the STARTTLS (RFC3207) extension.
    TLSConfig *tls.Config

    // Auth specifies an optional callback function that is called
    // when a client attempts to authenticate. If left nil (the default)
    // then the AUTH extension will not be supported.
    Auth func(username, password, remoteAddress string) error

    // Addressable specifies an optional callback function that is called
    // when a client attempts to send a message to the given address. This
    // allows the server to refuse messages that it doesn't own. If left nil
    // (the default) then the server will assume true
    Addressable func(user, address string) bool

    // Processors is a map of current supported commands' processor for incomming
    // SMTP messages/lines.
    Processors map[string]Processor

    // Maximum size of the DATA command in bytes
    MaxBodySize int64
}

Server is our main server handler

func (*Server) ListenAndServe Uses

func (srv *Server) ListenAndServe() error

ListenAndServe start serving the incoming data

func (*Server) ListenAndServeTLS Uses

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

ListenAndServeTLS start serving the incoming tls connection

func (*Server) Serve Uses

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

Serve start accepting the incoming connections

Package smtpsrv imports 12 packages (graph) and is imported by 2 packages. Updated 2018-11-12. Refresh now. Tools for package owners.