smtpd

package module
v0.0.0-...-99ac37b Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: MIT Imports: 18 Imported by: 0

README

smtpd

Go library for implementing simple SMTP servers. It's responsible for handling the SMTP server side protocol, nothing more, nothing less.

Usage

Create a type that implements the smtpd.Handler interface.

Create a smtp.Server instance with specific options and a listener.

Pass each connection together with a handler instance to ServeSMTP().

Testing

For testing authentication a TLS connection is used. Create a self-signed certificate before running the tests:

mkdir testdata
openssl genrsa 2048 > testdata/key.pem
openssl req -x509 -new -key key.pem > testdata/cert.pem

Documentation

Overview

Package smtpd implements the SMTP server protocol.

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

Debug can be set to true to print SMTP traces to the default Logger in package log.

View Source
var DefaultHostname, _ = os.Hostname()

DefaultHostname is used in the banner greeting when Server#hostname is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// Connect is called after connecting
	Connect(source string) error

	// Hello is called after EHLO/HELO
	Hello(hostname string) error

	// Authenticate is called after AUTH
	//Authenticate(identity, username, password_or_response string) error
	AuthUser(identity, username string) (password string, err error)

	// Sender is called after MAIL FROM
	Sender(address string) error

	// Recipient is called after RCPT TO
	Recipient(address string) error

	// Message is called after DATA. The reader returns the message data
	// after dot unstuffing. The final ".\r\n" is not included in the data.
	// When the complete message is consumed io.EOF is returned. It's not
	// required to consume all data. Any remaining data will be discarded
	// after Message() returns and the reader will become invalid.
	Message(reader io.Reader) error
}

Handler should be implemented by the application for handling SMTP command parameters and message data on a connection.

Each member can return an error to reject the command or to indicate processing failure. If the error text starts with a three digit status code, then the error text is returned as-is in the SMTP reply. If the error does not start with three digits, then "451 Requested action aborted: " is returned in the SMTP reply with the error text appended.

type Server

type Server struct {
	// Hostname to use in responses
	Hostname string

	// Set to enable STARTTLS
	// must include at least one certificate or else set GetCertificate
	TLSConfig *tls.Config

	// Set to enable PIPELINING
	Pipelining bool
}

Server represents an SMTP server configuration.

func (*Server) ServeSMTP

func (s *Server) ServeSMTP(conn net.Conn, handler Handler) error

ServeSMTP should be called by the application for each incoming connection.

The application provides a new instance of the Handler interface that can be used to process command parameters and read the message data.

The application should close the connection after ServeSMTP returns.

Jump to

Keyboard shortcuts

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