Package opensmtpd implements OpenSMTPD-extras in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

32 lines
688 B

package opensmtpd
import "strings"
func ExampleFilter() {
// 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()
}