smtp

package
v0.9.24 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DNSBLTimeout is the timeout for DNSBL requests
	DNSBLTimeout = 5 * time.Second
	// DNSBLDefaultSignal is the default signal for DNSBLs
	DNSBLDefaultSignal = "127.0.0.2"
)
View Source
const (
	// NoUserCode SMTP code
	NoUserCode = 550
	// BannedCode SMTP code
	BannedCode = 554
	// GreylistCode SMTP code
	GreylistCode = 451
	// RBLCode SMTP code
	RBLCode = 450
)
View Source
const (
	// Incoming is the direction of the email
	Incoming = "incoming"
	// Outgoing is the direction of the email
	Outoing = "outgoing"
)

Variables

View Source
var (
	// NoUserEnhancedCode enhanced SMTP code
	NoUserEnhancedCode = smtp.EnhancedCode{5, 5, 0}
	// BannedEnhancedCode enhanced SMTP code
	BannedEnhancedCode = smtp.EnhancedCode{5, 5, 4}
	// GreylistEnhancedCode is GraylistCode in enhanced code notation
	GreylistEnhancedCode = smtp.EnhancedCode{4, 5, 1}
	// RBLEnhancedCode is RBLCode in enhanced code notation
	RBLEnhancedCode = smtp.EnhancedCode{4, 5, 0}
	// ErrBanned returned to banned hosts
	ErrBanned = &smtp.SMTPError{
		Code:         BannedCode,
		EnhancedCode: BannedEnhancedCode,
		Message:      "please, don't bother me anymore, kupo.",
	}
	// ErrNoUser returned when no such mailbox found
	ErrNoUser = &smtp.SMTPError{
		Code:         NoUserCode,
		EnhancedCode: NoUserEnhancedCode,
		Message:      "no such user here, kupo.",
	}
	// ErrGreylisted returned when the host is graylisted
	ErrGreylisted = &smtp.SMTPError{
		Code:         GreylistCode,
		EnhancedCode: GreylistEnhancedCode,
		Message:      "You have been greylisted, try again a bit later.",
	}
	// ErrRBL returned when the host is blacklisted
	ErrRBL = &smtp.SMTPError{
		Code:         RBLCode,
		EnhancedCode: RBLEnhancedCode,
		Message:      "You are blacklisted, kupo.",
	}
	// ErrInvalidEmail for invalid emails :)
	ErrInvalidEmail = errors.New("please, provide valid email address")
)
View Source
var DNSBLs = map[string][]string{
	"b.barracudacentral.org":  {DNSBLDefaultSignal},
	"bl.spamcop.net":          {DNSBLDefaultSignal, "127.0.0.3"},
	"ix.dnsbl.manitu.net":     {DNSBLDefaultSignal},
	"psbl.surriel.com":        {DNSBLDefaultSignal},
	"rbl.interserver.net":     {DNSBLDefaultSignal},
	"spam.dnsbl.anonmails.de": {DNSBLDefaultSignal},
	"zen.spamhaus.org":        {DNSBLDefaultSignal, "127.0.0.3", "127.0.0.4", "127.0.0.5", "127.0.0.6", "127.0.0.7", "127.0.0.9"},
	"rbl.your-server.de":      {DNSBLDefaultSignal},
}

DNSBLs is a list of Domain Name System Blacklists with list of signals they use

Functions

func CheckDNSBLs

func CheckDNSBLs(ctx context.Context, log *zerolog.Logger, addr net.Addr, optionalTimeout ...time.Duration) (blocked bool, reasons []string)

CheckDNSBLs checks if the given IP address is listed in any of the DNSBLs, and returns a decision, based on the results

Types

type Caller

type Caller interface {
	SetSendmail(func(string, string, string, *url.URL) error)
}

Caller is Sendmail caller

type Client

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

SMTP client

func (Client) Send

func (c Client) Send(from, to, data string, relayOverride *url.URL) error

Send email

type Config

type Config struct {
	Domains []string
	Port    string

	TLSCerts    []string
	TLSKeys     []string
	TLSPort     string
	TLSRequired bool

	Logger  *zerolog.Logger
	MaxSize int
	Bot     matrixbot
	Callers []Caller
	Relay   *RelayConfig
}

type DNSBLRequest

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

DNSBLRequest is a request to check if an IP address is listed in any of the DNSBLs

type DNSBLResult

type DNSBLResult struct {
	RBL     string
	Reasons string
	Listed  bool
	Error   bool
}

type Listener

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

Listener that rejects connections from banned hosts

func NewListener

func NewListener(
	port string,
	tlsConfig *tls.Config,
	isBanned func(context.Context, net.Addr) bool,
	log *zerolog.Logger,
) (*Listener, error)

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*Listener) SetTLSConfig

func (l *Listener) SetTLSConfig(cfg *tls.Config)

type MailSender

type MailSender interface {
	Send(from, to, data string, relayOverride *url.URL) error
}

type Manager

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

func NewManager

func NewManager(cfg *Config) *Manager

NewManager creates new SMTP server manager

func (*Manager) Start

func (m *Manager) Start() error

Start SMTP server

func (*Manager) Stop

func (m *Manager) Stop()

Stop SMTP server

type PlainAuthServer

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

PlainAuthServer is a server implementation of the PLAIN authentication mechanism. It's a modified version of the original plainServer from https://github.com/emersion/go-sasl package (MIT License) ref: https://github.com/emersion/go-sasl/blob/e73c9f7bad438a9bf3f5b28e661b74d752ecafdd/plain.go The reason for modification is to extend automatic banning mechanism of Postmoogle, as the original implementation doesn't provide a way to return an error to the caller before the actual authentication process.

func NewPlainAuthServer

func NewPlainAuthServer(ctx context.Context, bot matrixbot, conn *smtp.Conn, auth sasl.PlainAuthenticator) *PlainAuthServer

NewPlainAuthServer creates a new PLAIN authentication server.

func (*PlainAuthServer) Next

func (a *PlainAuthServer) Next(response []byte) (challenge []byte, done bool, err error)

type RelayConfig

type RelayConfig struct {
	Host     string
	Port     string
	Username string
	Password string
}

type TLSConfig

type TLSConfig struct {
	Listener *Listener
	Config   *tls.Config
	Certs    []string
	Keys     []string
	Port     string
	Mu       sync.Mutex
}

Jump to

Keyboard shortcuts

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