diff --git a/models/smtp.go b/models/smtp.go index b2e45459..8ca8485b 100644 --- a/models/smtp.go +++ b/models/smtp.go @@ -101,6 +101,7 @@ func (s *SMTP) GetDialer() (mailer.Dialer, error) { if len(hp) < 2 { hp = append(hp, "25") } + host := hp[0] // Any issues should have been caught in validation, but we'll // double check here. port, err := strconv.Atoi(hp[1]) @@ -108,9 +109,9 @@ func (s *SMTP) GetDialer() (mailer.Dialer, error) { log.Error(err) return nil, err } - d := gomail.NewDialer(hp[0], port, s.Username, s.Password) + d := gomail.NewDialer(host, port, s.Username, s.Password) d.TLSConfig = &tls.Config{ - ServerName: s.Host, + ServerName: host, InsecureSkipVerify: s.IgnoreCertErrors, } hostname, err := os.Hostname() diff --git a/models/smtp_test.go b/models/smtp_test.go index e6552a9e..7ffbaadf 100644 --- a/models/smtp_test.go +++ b/models/smtp_test.go @@ -73,7 +73,7 @@ func (s *ModelsSuite) TestSMTPGetDialer(ch *check.C) { dialer := d.(*Dialer).Dialer ch.Assert(dialer.Host, check.Equals, host) ch.Assert(dialer.Port, check.Equals, port) - ch.Assert(dialer.TLSConfig.ServerName, check.Equals, smtp.Host) + ch.Assert(dialer.TLSConfig.ServerName, check.Equals, host) ch.Assert(dialer.TLSConfig.InsecureSkipVerify, check.Equals, smtp.IgnoreCertErrors) }