forked from alash3al/go-smtpsrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.go
34 lines (27 loc) · 861 Bytes
/
backend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package smtpsrv
import (
"errors"
"github.com/emersion/go-smtp"
)
// The Backend implements SMTP server methods.
type Backend struct {
handler HandlerFunc
auther AuthFunc
}
func NewBackend(auther AuthFunc, handler HandlerFunc) *Backend {
return &Backend{
handler: handler,
auther: auther,
}
}
// Login handles a login command with username and password.
func (bkd *Backend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
if nil == bkd.auther {
return nil, errors.New("invalid command specified")
}
return NewSession(state, bkd.handler, &username, &password), nil
}
// AnonymousLogin requires clients to authenticate using SMTP AUTH before sending emails
func (bkd *Backend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error) {
return NewSession(state, bkd.handler, nil, nil), nil
}