smtp

package
v0.0.0-...-bf75c1d Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package smtp provides a configurable SMTP server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// EmptyReply is a response that is not sent to the client.
	EmptyReply = &Response{0, nil, true}

	// StartTLSReply is returned when TLS negotiation should be started.
	StartTLSReply = &Response{220, []string{"Ready to start TLS"}, false}

	// QuitReply is returned when the connection to the client should be closed.
	QuitReply = &Response{221, []string{"Closing transmission channel"}, false}

	// OkReply is returned when an SMTP command is successful.
	OkReply = &Response{250, []string{"OK"}, true}

	// VrfyNotImplemented is returned in response to a VRFY command
	VrfyNotImplemented = &Response{252, []string{"VRFY not implemented"}, true}

	// StartMailInput is returned when the server is ready to receive a mail message.
	StartMailInput = &Response{354, []string{"Start mail input"}, false}

	// ServiceNotAvailable is returned when the server is out of order.
	ServiceNotAvailable = &Response{421, []string{"Service not available, closing transmission channel"}, false}

	// LocalError is returned when an internal error occurs.
	LocalError = &Response{451, []string{"Action aborted, local error in processing"}, false}

	// SyntaxError is returned when the SMTP parser detects an error.
	SyntaxError = &Response{500, []string{"Syntax error"}, false}

	// ParameterSyntaxError is returned when the SMTP parser detects and error with a command parameter.
	ParameterSyntaxError = &Response{501, []string{"Syntax error"}, false}

	// CommandNotImplemented is returned when an unsupported SMTP command is received.
	CommandNotImplemented = &Response{502, []string{"Command not implemented"}, false}

	// BadSequenceCommands is returned when a supported but unexpected command arrives.
	BadSequenceCommands = &Response{503, []string{"Bad sequence of commands"}, false}

	// NoSuchUser is returned when the receipient is unknown.
	NoSuchUser = &Response{550, []string{"No such user"}, true}

	// BadHello is returned when the client identification does not match its reverse DNS lookup.
	BadHello = &Response{550, []string{"Bad HELO"}, true}

	// BadFcrdns is returned when the client reverse DNS lookup does not
	// resolve to the client IP address.
	BadFcrdns = &Response{550, []string{"FCRDNS failure"}, true}

	// IPOnBlocklist is returned when the client IP is on an SMTP blocklist.
	IPOnBlocklist = &Response{554, []string{"IP on blocklist"}, true}

	// DomainOnBlocklist is returned when a domain is on an SMTP blocklist.
	DomainOnBlocklist = &Response{554, []string{"Domain on blocklist"}, true}

	// NoValidRecipients is returned during pipelining when a DATA command
	// is received but no valid recipients are available
	NoValidRecipients = &Response{554, []string{"No valid recipients given"}, false}
)
View Source
var EmptyTracer = emptyTracer{}

EmptyTracer turns off SMTP tracing -- this is the default.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// Session should return a SessionHandler that will be used to control
	// a single SMTP session and a SessionTracer that can be used to trace
	// the I/O the SMTP session.
	Session() (SessionHandler, SessionTracer)
}

A Handler is called by the smtp server at the start of every SMTP session. The Handler is expected to hold values that are common to all SMTP sessions e.g database connections.

type MailboxParts

type MailboxParts struct {
	Local       string
	Domain      string
	AddrLiteral string
}

MailboxParts contains a parsed mailbox that has been split into parts.

func ParseMailbox

func ParseMailbox(mbox string) (MailboxParts, error)

ParseMailbox parses a mailbox string into local and domain parts.

type OptionFn

type OptionFn func(s *Server) error

An OptionFn is used to configure the SMTP server.

func WithAddress

func WithAddress(address string) OptionFn

WithAddress sets the SMTP address and port of the Server.

func WithFqdn

func WithFqdn(fqdn string) OptionFn

WithFqdn sets the Fully Qualified Domain Name of the Server.

func WithHandler

func WithHandler(h Handler) OptionFn

WithHandler sets a struct that will handle SMTP callbacks.

func WithTLS

func WithTLS(certFile, keyFile string) OptionFn

WithTLS sets the TLS configuration of the Server and enables the STARTTLS ESMTP extension.

type Response

type Response struct {
	Code      uint16
	Lines     []string
	CanBuffer bool
}

Response contains the unserialized response to an SMTP command.

func (*Response) IsOk

func (r *Response) IsOk() bool

IsOk indicates if a Response is a successful response.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an SMTP server.

func NewServer

func NewServer(options ...OptionFn) (*Server, error)

NewServer creates a new SMTP server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe()

ListenAndServe starts an SMTP and does not return.

type SessionHandler

type SessionHandler interface {
	// Hello is called when the server receives a client HELO or EHLO. It
	// is expected that this function checks that the fqdn and ip address
	// are valid.
	Hello(ip net.IP, fqdn string) *Response
	// MailFrom is called when the server receives a MAIL command
	MailFrom(ip net.IP, fqdn, reversePath string) *Response
	// RcptTo is called when the server receives a RCPT command. It is expected
	// that this function checks that the recipient is valid.
	RcptTo(fqdn, reversePath, recipient string) *Response
	// Data is called when the server receives message data. This function should
	// return a WriteCloser that the SMTP server will write the message data to.
	Data(reversePath string, recipients []string) (io.WriteCloser, *Response)
	// End is called when the SMTP session has ended
	End()
}

A SessionHandler is called by the smtp server during an SMTP session. Structs that implement SessionHandler can hold state that is specific to a single session.

type SessionTracer

type SessionTracer interface {
	// Data from client
	Client([]byte)
	// Data from server
	Server([]byte)
	// Server sends data to client
	ServerFlush()
	// End of smtp session
	Close()
}

A SessionTracer is used to trace a single SMTP session.

Jump to

Keyboard shortcuts

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