add LOGIN auth method

This commit is contained in:
Aine
2022-11-08 17:07:05 +02:00
parent 0e10f7caba
commit ebb648807d

View File

@@ -6,6 +6,7 @@ import (
"os"
"time"
"github.com/emersion/go-sasl"
"github.com/emersion/go-smtp"
"gitlab.com/etke.cc/go/logger"
)
@@ -57,6 +58,19 @@ func NewServer(cfg *Config) *Server {
if log.GetLevel() == "DEBUG" || log.GetLevel() == "TRACE" {
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{
msa: s,