Skip to content

Commit

Permalink
Merge pull request #18 from k1LoW/option
Browse files Browse the repository at this point in the history
Support option
  • Loading branch information
k1LoW committed Mar 29, 2024
2 parents 90c2461 + 8a03ad9 commit 4f1d8cb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions smtptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,31 @@ type Server struct {
wg sync.WaitGroup
}

func NewServer() (*Server, error) {
return newServer(&backend{})
type Option func(*backend) error

func WithPlainAuth(username, password string) Option {
return func(be *backend) error {
be.username = &username
be.password = &password
return nil
}
}

func WithOnReceiveFunc(fn onReceiveFunc) Option {
return func(be *backend) error {
be.onReceiveFuncs = append(be.onReceiveFuncs, fn)
return nil
}
}

func NewServer(opts ...Option) (*Server, error) {
be := &backend{}
for _, opt := range opts {
if err := opt(be); err != nil {
return nil, err
}
}
return newServer(be)
}

func NewServerWithAuth() (*Server, netsmtp.Auth, error) {
Expand Down Expand Up @@ -256,6 +279,7 @@ func (s *Server) RawMessages() []io.Reader {
return raws
}

// Deprecated
func (s *Server) OnReceive(fn func(from, to string, recipients []string, msg *mail.Message) error) {
s.backend.onReceiveFuncs = append(s.backend.onReceiveFuncs, fn)
}
Expand Down

0 comments on commit 4f1d8cb

Please sign in to comment.