diff --git a/common/constants.go b/common/constants.go index 4000e08..85ecadd 100644 --- a/common/constants.go +++ b/common/constants.go @@ -75,6 +75,7 @@ var LogConsumeEnabled = true var SMTPServer = "" var SMTPPort = 587 +var SMTPSSLEnabled = false var SMTPAccount = "" var SMTPFrom = "" var SMTPToken = "" diff --git a/common/email.go b/common/email.go index 5d3ef0d..13345d8 100644 --- a/common/email.go +++ b/common/email.go @@ -24,7 +24,7 @@ func SendEmail(subject string, receiver string, content string) error { addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort) to := strings.Split(receiver, ";") var err error - if SMTPPort == 465 { + if SMTPPort == 465 || SMTPSSLEnabled { tlsConfig := &tls.Config{ InsecureSkipVerify: true, ServerName: SMTPServer, diff --git a/model/option.go b/model/option.go index 46e41da..2ccfe03 100644 --- a/model/option.go +++ b/model/option.go @@ -50,6 +50,7 @@ func InitOptionMap() { common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort) common.OptionMap["SMTPAccount"] = "" common.OptionMap["SMTPToken"] = "" + common.OptionMap["SMTPSSLEnabled"] = strconv.FormatBool(common.SMTPSSLEnabled) common.OptionMap["Notice"] = "" common.OptionMap["About"] = "" common.OptionMap["HomePageContent"] = "" @@ -199,6 +200,8 @@ func updateOptionMap(key string, value string) (err error) { constant.CheckSensitiveOnCompletionEnabled = boolValue case "StopOnSensitiveEnabled": constant.StopOnSensitiveEnabled = boolValue + case "SMTPSSLEnabled": + common.SMTPSSLEnabled = boolValue } } switch key { diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index c305d2c..8d13ef1 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -42,6 +42,7 @@ const SystemSetting = () => { TurnstileSecretKey: '', RegisterEnabled: '', EmailDomainRestrictionEnabled: '', + SMTPSSLEnabled: '', EmailDomainWhitelist: [], // telegram login TelegramOAuthEnabled: '', @@ -98,6 +99,7 @@ const SystemSetting = () => { case 'TelegramOAuthEnabled': case 'TurnstileCheckEnabled': case 'EmailDomainRestrictionEnabled': + case 'SMTPSSLEnabled': case 'RegisterEnabled': value = inputs[key] === 'true' ? 'false' : 'true'; break; @@ -134,7 +136,7 @@ const SystemSetting = () => { } if ( name === 'Notice' || - name.startsWith('SMTP') || + (name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') || name === 'ServerAddress' || name === 'EpayId' || name === 'EpayKey' || @@ -570,6 +572,14 @@ const SystemSetting = () => { placeholder='敏感信息不会发送到前端显示' /> + + + 保存 SMTP 设置