add LOGIN auth method
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"gitlab.com/etke.cc/go/logger"
|
"gitlab.com/etke.cc/go/logger"
|
||||||
)
|
)
|
||||||
@@ -57,6 +58,19 @@ func NewServer(cfg *Config) *Server {
|
|||||||
if log.GetLevel() == "DEBUG" || log.GetLevel() == "TRACE" {
|
if log.GetLevel() == "DEBUG" || log.GetLevel() == "TRACE" {
|
||||||
s.Debug = os.Stdout
|
s.Debug = os.Stdout
|
||||||
}
|
}
|
||||||
|
// LOGIN auth method, ref: https://github.com/emersion/go-smtp/issues/41#issuecomment-493601465
|
||||||
|
s.EnableAuth(sasl.Login, func(conn *smtp.Conn) sasl.Server {
|
||||||
|
return sasl.NewLoginServer(func(username, password string) error {
|
||||||
|
state := conn.State()
|
||||||
|
session, err := receiver.Login(&state, username, password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.SetSession(session)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
server := &Server{
|
server := &Server{
|
||||||
msa: s,
|
msa: s,
|
||||||
|
|||||||
Reference in New Issue
Block a user