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.

filter_test.go 688B

1234567891011121314151617181920212223242526272829303132
  1. package opensmtpd
  2. import "strings"
  3. func ExampleFilter() {
  4. // Build our filter
  5. filter := &Filter{
  6. HELO: func(session *Session, helo string) error {
  7. if helo == "test" {
  8. return session.Reject(FilterOK, 0)
  9. }
  10. return session.Accept()
  11. },
  12. }
  13. // Add another hook
  14. filter.MAIL = func(session *Session, user, domain string) error {
  15. if strings.ToLower(domain) == "example.org" {
  16. return session.Reject(FilterOK, 0)
  17. }
  18. return session.Accept()
  19. }
  20. // Register our filter with smtpd. This step is optional and will
  21. // be performed by Serve() if omitted.
  22. if err := filter.Register(); err != nil {
  23. panic(err)
  24. }
  25. // And keep serving until smtpd stops
  26. filter.Serve()
  27. }