diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mailer/mailer.go | 14 | ||||
-rw-r--r-- | modules/setting/setting.go | 16 |
2 files changed, 17 insertions, 13 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 792e443543..f658427c1a 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -72,15 +72,17 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte) return err } - cert, err := tls.LoadX509KeyPair(settings.CertFile, settings.KeyFile) - if err != nil { - return err - } - tlsconfig := &tls.Config{ InsecureSkipVerify: settings.SkipVerify, ServerName: host, - Certificates: []tls.Certificate{cert}, + } + + if settings.UseCertificate { + cert, err := tls.LoadX509KeyPair(settings.CertFile, settings.KeyFile) + if err != nil { + return err + } + tlsconfig.Certificates = []tls.Certificate{cert} } conn, err := net.Dial("tcp", net.JoinHostPort(host, port)) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index cf19b1aa8b..32284b4236 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -451,6 +451,7 @@ type Mailer struct { From string User, Passwd string SkipVerify bool + UseCertificate bool CertFile, KeyFile string } @@ -479,13 +480,14 @@ func newMailService() { } MailService = &Mailer{ - Name: sec.Key("NAME").MustString(AppName), - Host: sec.Key("HOST").String(), - User: sec.Key("USER").String(), - Passwd: sec.Key("PASSWD").String(), - SkipVerify: sec.Key("SKIP_VERIFY").MustBool(), - CertFile: sec.Key("CERT_FILE").String(), - KeyFile: sec.Key("KEY_FILE").String(), + Name: sec.Key("NAME").MustString(AppName), + Host: sec.Key("HOST").String(), + User: sec.Key("USER").String(), + Passwd: sec.Key("PASSWD").String(), + SkipVerify: sec.Key("SKIP_VERIFY").MustBool(), + UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(), + CertFile: sec.Key("CERT_FILE").String(), + KeyFile: sec.Key("KEY_FILE").String(), } MailService.From = sec.Key("FROM").MustString(MailService.User) log.Info("Mail Service Enabled") |