mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-27 08:32:15 +00:00
Merge pull request #418 from tbouvet/master
Add support for smtp AUTH LOGIN
This commit is contained in:
commit
ec708124be
@ -17,6 +17,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -251,6 +252,12 @@ func (n *Email) auth(mechs string) (smtp.Auth, error) {
|
||||
return nil, fmt.Errorf("invalid address: %s", err)
|
||||
}
|
||||
return smtp.PlainAuth(identity, username, password, host), nil
|
||||
case "LOGIN":
|
||||
password := string(n.conf.AuthPassword)
|
||||
if password == "" {
|
||||
continue
|
||||
}
|
||||
return LoginAuth(username, password), nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
@ -813,3 +820,30 @@ func tmplHTML(tmpl *template.Template, data *template.Data, err *error) func(str
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
type loginAuth struct {
|
||||
username, password string
|
||||
}
|
||||
|
||||
func LoginAuth(username, password string) smtp.Auth {
|
||||
return &loginAuth{username, password}
|
||||
}
|
||||
|
||||
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
||||
return "LOGIN", []byte{}, nil
|
||||
}
|
||||
|
||||
// Used for AUTH LOGIN. (Maybe password should be encrypted)
|
||||
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
||||
if more {
|
||||
switch string(fromServer) {
|
||||
case "Username:":
|
||||
return []byte(a.username), nil
|
||||
case "Password:":
|
||||
return []byte(a.password), nil
|
||||
default:
|
||||
return nil, errors.New("unexpected server challenge")
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user