mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
Email Notifications: Add StartTLSPolicy config flag (#24574)
This commit is contained in:
parent
285ea7595d
commit
16297da298
@ -464,6 +464,7 @@ skip_verify = false
|
||||
from_address = admin@grafana.localhost
|
||||
from_name = Grafana
|
||||
ehlo_identity =
|
||||
startTLS_policy =
|
||||
|
||||
[emails]
|
||||
welcome_email_on_sign_up = false
|
||||
|
@ -454,6 +454,8 @@
|
||||
;from_name = Grafana
|
||||
# EHLO identity in SMTP dialog (defaults to instance_name)
|
||||
;ehlo_identity = dashboard.example.com
|
||||
# SMTP startTLS policy (defaults to 'OpportunisticStartTLS')
|
||||
;startTLS_policy = NoStartTLS
|
||||
|
||||
[emails]
|
||||
;welcome_email_on_sign_up = false
|
||||
|
@ -560,6 +560,9 @@ Name to be used when sending out emails, defaults to `Grafana`
|
||||
### ehlo_identity
|
||||
Name to be used as client identity for EHLO in SMTP dialog, defaults to instance_name.
|
||||
|
||||
### startTLS_policy
|
||||
Either "OpportunisticStartTLS", "MandatoryStartTLS", "NoStartTLS". Default is "OpportunisticStartTLS"
|
||||
|
||||
## [log]
|
||||
|
||||
### mode
|
||||
|
@ -111,6 +111,7 @@ func (ns *NotificationService) createDialer() (*gomail.Dialer, error) {
|
||||
|
||||
d := gomail.NewDialer(host, iPort, ns.Cfg.Smtp.User, ns.Cfg.Smtp.Password)
|
||||
d.TLSConfig = tlsconfig
|
||||
d.StartTLSPolicy = getStartTLSPolicy(ns.Cfg.Smtp.StartTLSPolicy)
|
||||
|
||||
if ns.Cfg.Smtp.EhloIdentity != "" {
|
||||
d.LocalName = ns.Cfg.Smtp.EhloIdentity
|
||||
@ -120,6 +121,17 @@ func (ns *NotificationService) createDialer() (*gomail.Dialer, error) {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func getStartTLSPolicy(policy string) gomail.StartTLSPolicy {
|
||||
switch policy {
|
||||
case "NoStartTLS":
|
||||
return -1
|
||||
case "MandatoryStartTLS":
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *NotificationService) buildEmailMessage(cmd *models.SendEmailCommand) (*Message, error) {
|
||||
if !ns.Cfg.Smtp.Enabled {
|
||||
return nil, models.ErrSmtpNotEnabled
|
||||
|
@ -1,16 +1,17 @@
|
||||
package setting
|
||||
|
||||
type SmtpSettings struct {
|
||||
Enabled bool
|
||||
Host string
|
||||
User string
|
||||
Password string
|
||||
CertFile string
|
||||
KeyFile string
|
||||
FromAddress string
|
||||
FromName string
|
||||
EhloIdentity string
|
||||
SkipVerify bool
|
||||
Enabled bool
|
||||
Host string
|
||||
User string
|
||||
Password string
|
||||
CertFile string
|
||||
KeyFile string
|
||||
FromAddress string
|
||||
FromName string
|
||||
EhloIdentity string
|
||||
StartTLSPolicy string
|
||||
SkipVerify bool
|
||||
|
||||
SendWelcomeEmailOnSignUp bool
|
||||
TemplatesPattern string
|
||||
@ -27,6 +28,7 @@ func (cfg *Cfg) readSmtpSettings() {
|
||||
cfg.Smtp.FromAddress = sec.Key("from_address").String()
|
||||
cfg.Smtp.FromName = sec.Key("from_name").String()
|
||||
cfg.Smtp.EhloIdentity = sec.Key("ehlo_identity").String()
|
||||
cfg.Smtp.StartTLSPolicy = sec.Key("startTLS_policy").String()
|
||||
cfg.Smtp.SkipVerify = sec.Key("skip_verify").MustBool(false)
|
||||
|
||||
emails := cfg.Raw.Section("emails")
|
||||
|
Loading…
Reference in New Issue
Block a user