smtpd

package module
v0.0.0-...-e8e3e70 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: BSD-2-Clause, BSD-3-Clause Imports: 13 Imported by: 0

README

Just an experiment, don't use this. Adapted from github.com/bradfitz/go-smtpd.

Documentation

Overview

Package smtpd provides an SMTP server for receiving e-mails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HeloType   string
	HeloHost   string
	Pregreeted bool
	// contains filtered or unexported fields
}

func (Client) Addr

func (c Client) Addr() net.Addr

type Connection

type Connection interface {
	Addr() net.Addr
}

Connection is implemented by the SMTP library and provided to callers customizing their own Servers.

type Envelope

type Envelope struct {
	Client     Client
	Sender     MailAddress
	Recipients []MailAddress
	Data       []byte
}

func (*Envelope) AddReceivedHeader

func (e *Envelope) AddReceivedHeader(serverHostname string)

func (*Envelope) AddRecipient

func (e *Envelope) AddRecipient(rcpt MailAddress)

type MailAddress

type MailAddress string

func (MailAddress) Email

func (a MailAddress) Email() string

func (MailAddress) Hostname

func (a MailAddress) Hostname() string

type SMTPError

type SMTPError string

SMTPReply is a string to be sent to a client as an SMTP reply. E.g. "550 5.7.1 IP address blacklisted". SMTPReply is meant to be used as a return value in the callback functions in Server (e.g. OnMailFrom) that return an error. Bad things will happen if an SMTPError is not an SMTP error reply.

func (SMTPError) Error

func (e SMTPError) Error() string

type Server

type Server struct {
	Addr         string        // TCP address to listen on, ":25" if empty
	Hostname     string        // optional Hostname to announce; "" to use system hostname
	ReadTimeout  time.Duration // optional read timeout
	WriteTimeout time.Duration // optional write timeout

	// PregreetDelay is the amount of time to wait after sending the initial
	// "220-" line before sending the final "220 " line.
	PregreetDelay time.Duration

	// OnNewConnection, if non-nil, is called on new connections.
	// If it returns non-nil, the connection is closed.
	OnNewConnection func(c Connection) error

	// OnMailFrom, if non-nil, is called on MAIL FROM.
	// If the callback returns an SMTPError, the MAIL FROM address is not added
	// to the envelope, and the SMTPError is sent to the client as reply to
	// MAIL FROM.
	// If the callback returns a non-nil value that is not an SMTPError,
	// the address is also not added to the envelope, and the server replies
	// with "550 5.0.0 unacceptable sender" (permanent error).
	OnMailFrom func(c Connection, from MailAddress) error

	// OnRcptTo, if non-nil, is called on RCPT TO.
	// If it returns non-nil, the recipient is not rejected and not added
	// to the Envelope.
	// If the callback returns an SMTPError, the RCPT TO address is not added
	// to the envelope, and the SMTPError is sent to the client as reply to
	// MAIL FROM.
	// If the callback returns a non-nil value that is not an SMTPError,
	// the address is also not added to the envelope, and the server replies
	// with "550 5.0.0 unacceptable sender" (permanent error).
	OnRcptTo func(c Connection, rcpt MailAddress) error

	// Deliver is called when DATA is finished and the mail is ready to be
	// accepted. If it returns non-nil, the mail is rejected.
	Deliver func(env *Envelope) error

	// Log is used for logging within the Server.
	// If nil, logging is disabled.
	Log *log.Logger
}

Server is an SMTP server.

func (*Server) Listen

func (srv *Server) Listen() (net.Listener, error)

Listen listens on the TCP network address srv.Addr, but does not call Serve.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(ctx context.Context) error

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":25" is used.

func (*Server) Logf

func (srv *Server) Logf(format string, v ...interface{})

Logf calls Printf on srv.Log with the provided arguments if srv.Log is not nil.

func (*Server) Serve

func (srv *Server) Serve(ctx context.Context, ln net.Listener) error

Serve handles incoming SMTP connections on the provided listener. Serve blocks until the context is cancelled and all connections have been gracefully shut down. Returns a non-nil error if a fatal accept error occurs.

Jump to

Keyboard shortcuts

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