smtp

package
v0.0.0-...-840fb12 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package smtp implements an SMTP server for Freemail.

Index

Constants

View Source
const (
	DefaultPort     = 3025
	DefaultHostname = "localhost"
	ReadTimeout     = 5 * time.Minute
	WriteTimeout    = 5 * time.Minute
	MaxMessageSize  = 10 * 1024 * 1024 // 10MB
	MaxRecipients   = 100
)

Server configuration

Variables

This section is empty.

Functions

func ParseHeaders

func ParseHeaders(data []byte) (textproto.MIMEHeader, []byte, error)

ParseHeaders parses raw headers into a textproto.MIMEHeader

func SerializeMessage

func SerializeMessage(m *freemail.Message) ([]byte, error)

SerializeMessage converts a message to bytes for sending

Types

type Authenticator

type Authenticator interface {
	// Authenticate validates username and password
	Authenticate(username, password string) (bool, error)

	// GetAccountID returns the account ID for a username
	GetAccountID(username string) string
}

Authenticator interface for validating credentials

type Connection

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

Connection represents a client SMTP connection

func NewConnection

func NewConnection(conn net.Conn, server *Server) *Connection

NewConnection creates a new SMTP connection

func (*Connection) Close

func (c *Connection) Close() error

Close closes the connection

func (*Connection) Handle

func (c *Connection) Handle()

Handle handles the SMTP session

type FreemailAuthenticator

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

FreemailAuthenticator authenticates users against Freemail accounts

func NewFreemailAuthenticator

func NewFreemailAuthenticator(am *freemail.AccountManager) *FreemailAuthenticator

NewFreemailAuthenticator creates a new Freemail authenticator

func (*FreemailAuthenticator) Authenticate

func (a *FreemailAuthenticator) Authenticate(username, password string) (bool, error)

Authenticate validates username and password

func (*FreemailAuthenticator) GetAccountID

func (a *FreemailAuthenticator) GetAccountID(username string) string

GetAccountID returns the account ID for a username

type FreemailHandler

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

FreemailHandler handles messages for Freemail delivery

func NewFreemailHandler

func NewFreemailHandler(am *freemail.AccountManager, tm *freemail.TransportManager, storage *freemail.Storage) *FreemailHandler

NewFreemailHandler creates a new Freemail message handler

func (*FreemailHandler) HandleMessage

func (h *FreemailHandler) HandleMessage(from string, to []string, data []byte) error

HandleMessage processes a submitted email message

type MessageHandler

type MessageHandler interface {
	// HandleMessage processes a submitted email message
	HandleMessage(from string, to []string, data []byte) error
}

MessageHandler interface for handling submitted messages

type Server

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

Server represents an SMTP server

func NewServer

func NewServer(port int, hostname string) *Server

NewServer creates a new SMTP server

func (*Server) GetAuthenticator

func (s *Server) GetAuthenticator() Authenticator

GetAuthenticator returns the authenticator

func (*Server) GetHandler

func (s *Server) GetHandler() MessageHandler

GetHandler returns the message handler

func (*Server) GetHostname

func (s *Server) GetHostname() string

GetHostname returns the server hostname

func (*Server) SetAuthenticator

func (s *Server) SetAuthenticator(auth Authenticator)

SetAuthenticator sets the authenticator

func (*Server) SetHandler

func (s *Server) SetHandler(handler MessageHandler)

SetHandler sets the message handler

func (*Server) Start

func (s *Server) Start() error

Start starts the SMTP server

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the SMTP server

type SessionState

type SessionState int

SessionState represents the state of an SMTP session

const (
	StateInit SessionState = iota
	StateGreeted
	StateAuthenticated
	StateMailFrom
	StateRcptTo
	StateData
)

Jump to

Keyboard shortcuts

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