Skip to content

Commit

Permalink
SMTP email notifier OnTest() fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Sep 20, 2019
1 parent 9d9f91f commit 15e3b83
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions notifiers/email.go
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
"html/template"
"net/smtp"
"time"
)

Expand Down Expand Up @@ -225,24 +224,6 @@ func (u *email) OnSave() error {

// OnTest triggers when this notifier has been saved
func (u *email) OnTest() error {
host := fmt.Sprintf("%v:%v", u.Host, u.Port)
dial, err := smtp.Dial(host)
if err != nil {
return err
}
if u.ApiKey != "true" {
err = dial.StartTLS(&tls.Config{InsecureSkipVerify: true})
if err != nil {
return err
}
}
if u.Username != "" || u.Password != "" {
auth := smtp.PlainAuth("", u.Username, u.Password, host)
err = dial.Auth(auth)
if err != nil {
return err
}
}
testService := &types.Service{
Id: 1,
Name: "Example Service",
Expand All @@ -261,11 +242,10 @@ func (u *email) OnTest() error {
To: u.Var2,
Subject: fmt.Sprintf("Service %v is Back Online", testService.Name),
Template: mainEmailTemplate,
Data: interface{}(testService),
Data: testService,
From: u.Var1,
}
err = u.dialSend(email)
return err
return u.dialSend(email)
}

func (u *email) dialSend(email *emailOutgoing) error {
Expand Down

0 comments on commit 15e3b83

Please sign in to comment.