added smtp auth machinery

This commit is contained in:
Christopher Ramey 2021-01-24 13:59:53 -09:00
parent e1df5ac487
commit 081ecb0607
2 changed files with 14 additions and 1 deletions

View File

@ -1,8 +1,8 @@
package alarm
import (
"fmt"
"alrm/alarm/email"
"fmt"
)
type Alarm interface {

View File

@ -21,6 +21,19 @@ func (a *AlarmEmail) Alarm(grp string, hst string, chk string, alerr error) erro
return err
}
if a.User != "" && a.Pass != "" {
hostname := a.SMTP
hn := strings.Split(a.SMTP, ":")
if len(hn) > 1 {
hostname = hn[0]
}
auth := smtp.PlainAuth("", a.User, a.Pass, hostname)
err = c.Auth(auth)
if err != nil {
return err
}
}
helo := "localhost"
tspl := strings.Split(a.From, "@")
if len(tspl) > 1 {