mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Only send test email when changing smtp values (#4394)
* Only send test email when changing smtp values * Update comment
This commit is contained in:
parent
33c5f0651c
commit
6cffd5438f
2 changed files with 13 additions and 3 deletions
1
changes/issue-4316-send-email-configured
Normal file
1
changes/issue-4316-send-email-configured
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Only send test email when changing smtp values
|
||||
|
|
@ -152,6 +152,8 @@ func (svc *Service) ModifyAppConfig(ctx context.Context, p []byte) (*fleet.AppCo
|
|||
return nil, err
|
||||
}
|
||||
|
||||
oldSmtpSettings := appConfig.SMTPSettings
|
||||
|
||||
// TODO(mna): this ports the validations from the old validationMiddleware
|
||||
// correctly, but this could be optimized so that we don't unmarshal the
|
||||
// incoming bytes twice.
|
||||
|
|
@ -172,9 +174,16 @@ func (svc *Service) ModifyAppConfig(ctx context.Context, p []byte) (*fleet.AppCo
|
|||
return nil, &badRequestError{message: err.Error()}
|
||||
}
|
||||
|
||||
if appConfig.SMTPSettings.SMTPEnabled || appConfig.SMTPSettings.SMTPConfigured {
|
||||
if err = svc.sendTestEmail(ctx, appConfig); err != nil {
|
||||
return nil, err
|
||||
// ignore the values for SMTPEnabled and SMTPConfigured
|
||||
oldSmtpSettings.SMTPEnabled = appConfig.SMTPSettings.SMTPEnabled
|
||||
oldSmtpSettings.SMTPConfigured = appConfig.SMTPSettings.SMTPConfigured
|
||||
|
||||
// if we enable SMTP and the settings have changed, then we send a test email
|
||||
if appConfig.SMTPSettings.SMTPEnabled {
|
||||
if oldSmtpSettings != appConfig.SMTPSettings || !appConfig.SMTPSettings.SMTPConfigured {
|
||||
if err = svc.sendTestEmail(ctx, appConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
appConfig.SMTPSettings.SMTPConfigured = true
|
||||
} else if appConfig.SMTPSettings.SMTPEnabled {
|
||||
|
|
|
|||
Loading…
Reference in a new issue