github.com/infraboard/keyauth@v0.8.1/apps/system/notify/mail/auth.go (about) 1 package mail 2 3 import ( 4 "errors" 5 "net/smtp" 6 "strings" 7 ) 8 9 type loginAuth struct { 10 username string 11 password string 12 } 13 14 func newLoginAuth(username, password string) smtp.Auth { 15 return &loginAuth{username, password} 16 } 17 18 func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { 19 return "LOGIN", []byte{}, nil 20 } 21 22 // Used for AUTH LOGIN. (Maybe password should be encrypted) 23 func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { 24 if more { 25 switch strings.ToLower(string(fromServer)) { 26 case "username:": 27 return []byte(a.username), nil 28 case "password:": 29 return []byte(a.password), nil 30 default: 31 return nil, errors.New("unexpected server challenge") 32 } 33 } 34 return nil, nil 35 }