Documentation ¶
Overview ¶
Package opensmtpd implements OpenSMTPD APIs
APIs in OpenSMTPD ¶
The APIs in OpenSMTPD are not stable and subject to change. The filter versions implemented by this package are tested against OpenSMTPD-portable version 6.0.3.
Filters ¶
Hooks for the various SMTP transaction stages. If a filter function is registered for a callback, the OpenSMTPD process expects a reply via the Session.Accept() or Session.Reject() calls. Failing to do so may result in a locked up mail server, you have been warned!
Index ¶
Examples ¶
Constants ¶
View Source
const ( FilterOK = iota FilterFail FilterClose )
View Source
const ( // FilterVersion is the supported filter API version FilterVersion = 52 // QueueVersion is the supported queue API version QueueVersion = 2 // TableVersion is the supported table API version TableVersion = 2 )
View Source
const ( ServiceNone = 0x000 ServiceAlias = 0x001 ServiceDomain = 0x002 ServiceCredentials = 0x004 ServiceNetaddr = 0x008 ServiceUserinfo = 0x010 ServiceSource = 0x020 ServiceMailaddr = 0x040 ServiceAddrname = 0x080 ServiceMailaddrMap = 0x100 ServiceRelayHost = 0x200 ServiceString = 0x400 ServiceAny = 0xfff )
Services
Variables ¶
View Source
var ( // Debug flag Debug bool )
Functions ¶
This section is empty.
Types ¶
type ConnectQuery ¶
ConnectQuery are the QUERY_CONNECT arguments
func (ConnectQuery) String ¶
func (q ConnectQuery) String() string
type Filter ¶
type Filter struct { // Connect callback Connect func(*Session, *ConnectQuery) error // HELO callback HELO func(*Session, string) error // MAIL FROM callback MAIL func(*Session, string, string) error // RCPT TO callback RCPT func(*Session, string, string) error // DATA callback DATA func(*Session) error // DataLine callback DataLine func(*Session, string) error // EOM (end of message) callback EOM func(*Session, uint32) error // Reset callback Reset func(*Session) error // Disconnect callback Disconnect func(*Session) error // Commit callback Commit func(*Session) error Name string Version uint32 // contains filtered or unexported fields }
Filter implements the OpenSMTPD filter API
Example ¶
// Build our filter filter := &Filter{ HELO: func(session *Session, helo string) error { if helo == "test" { return session.Reject(FilterOK, 0) } return session.Accept() }, } // Add another hook filter.MAIL = func(session *Session, user, domain string) error { if strings.ToLower(domain) == "example.org" { return session.Reject(FilterOK, 0) } return session.Accept() } // Register our filter with smtpd. This step is optional and will // be performed by Serve() if omitted. if err := filter.Register(); err != nil { panic(err) } // And keep serving until smtpd stops filter.Serve()
Output:
type Table ¶
type Table struct { // Update callback Update func() (int, error) // Check callback Check func(service int, params Dict, key string) (int, error) // Lookup callback Lookup func(service int, params Dict, key string) (string, error) // Fetch callback Fetch func(service int, params Dict) (string, error) // Close callback, called at stop Close func() error // contains filtered or unexported fields }
Table implements the OpenSMTPD table API
Example ¶
// In smtpd.conf: // // table aliases <name-of-filter>: // accept for local alias <aliases> ... aliases := map[string]string{ "root": "user@example.org", } table := &Table{ Lookup: func(service int, params Dict, key string) (string, error) { // We are only valid for aliases if service&ServiceAlias != 0 { return aliases[key], nil } return "", nil }, } table.Serve()
Output:
Source Files ¶
Click to show internal directories.
Click to hide internal directories.