2025-05-23 00:01:52 +05:30
|
|
|
package client
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/smtp"
|
|
|
|
|
"strings"
|
2025-09-09 15:44:27 +05:30
|
|
|
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/errors"
|
2025-05-23 00:01:52 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type loginAuth struct {
|
|
|
|
|
username string
|
|
|
|
|
password string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LoginAuth(username, password string) smtp.Auth {
|
|
|
|
|
return &loginAuth{username, password}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (auth *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
|
|
|
|
return "LOGIN", []byte{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (auth *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
|
|
|
|
if more {
|
|
|
|
|
switch strings.ToLower(string(fromServer)) {
|
|
|
|
|
case "username:":
|
|
|
|
|
return []byte(auth.username), nil
|
|
|
|
|
case "password:":
|
|
|
|
|
return []byte(auth.password), nil
|
|
|
|
|
default:
|
2025-09-09 15:44:27 +05:30
|
|
|
return nil, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, "unexpected server challenge")
|
2025-05-23 00:01:52 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|