smtp

package module
v0.0.0-...-0e58888 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2015 License: MIT Imports: 11 Imported by: 0

README

smtp

An smtp server in Go.

This is not finished. Do not use.

Documentation

Overview

Package smtp provides an SMTP server for receiving mail.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Start() (toClient string, err error)
	Auth(user, fromClient string) (ok bool)
}

func CramAuthenticator

func CramAuthenticator(a func(string) string) Authenticator

type Expander

type Expander func(string) []User

An Expander expands mailing lists into the list of Users who are in it.

type Handler

type Handler func(Message)

A Handler receives Messages when transactions are completed.

Example
var logger = func(message Message) {
	log.Printf("Recieved message from %s\n%s\n", message.Sender, message.Data)
}

s.Handle(logger)
Output:

type Message

type Message struct {
	Sender     string
	Recipients []string
	Data       []byte
}

type Server

type Server struct {
	CramAuthenticator func(string) string
	// contains filtered or unexported fields
}
Example
s, err := Listen(":25", "mx.test.local")
if err != nil {
	panic(err)
}

defer s.Close()

s.Handle(func(message Message) {
	// ...
})
Output:

func Listen

func Listen(laddr, name string) (*Server, error)

Listen creates a new Server listening at the local network address laddr and will announce itself to new connections with the name given.

func (*Server) Close

func (s *Server) Close() error

Close stops the Server from accepting new connections and listening.

func (*Server) Expand

func (s *Server) Expand(expander Expander)

Expand registers the Expander to be used when an EXPN command is issued to the Server. If an Expander was previously registered it is overwritten.

func (*Server) Handle

func (s *Server) Handle(handler Handler)

Handle registers a new Handler to the Server. All Handlers will be run for each Message received, on completion of a mail transaction.

func (*Server) Verify

func (s *Server) Verify(verifier Verifier)

Verify registers the Verifier to be used when a VRFY command is issued to the Server. If a Verifier was previously registered it is overwritten.

type User

type User struct {
	Name, Addr string
}

User represents an account that can receive mail with a name and address usually formatted as, e.g., "John Doe <john.doe@example.com>".

type Verifier

type Verifier func(string) User

A Verifier verifies whether its argument represents a user or email address on the system, and if so returns the details as a User; otherwise an empty User is returned.

Example
var users = []User{
	{"John Doe", "john.doe@example.com"},
	{"Jane Doe", "jane.doe@example.com"},
}

s.Verify(func(arg string) User {
	for _, user := range users {
		if user.Name == arg || user.Addr == arg {
			return user
		}
	}

	return User{}
})
Output:

Jump to

Keyboard shortcuts

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