diff --git a/common/constants.go b/common/constants.go index 6f3e770c..8c6c6b04 100644 --- a/common/constants.go +++ b/common/constants.go @@ -36,6 +36,7 @@ var RegisterEnabled = true var SMTPServer = "" var SMTPPort = 587 var SMTPAccount = "" +var SMTPFrom = "" var SMTPToken = "" var GitHubClientId = "" diff --git a/common/email.go b/common/email.go index 7e154090..af8a57a4 100644 --- a/common/email.go +++ b/common/email.go @@ -11,7 +11,7 @@ func SendEmail(subject string, receiver string, content string) error { "From: %s<%s>\r\n"+ "Subject: %s\r\n"+ "Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n", - receiver, SystemName, SMTPAccount, subject, content)) + receiver, SystemName, SMTPFrom, subject, content)) auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer) addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort) to := strings.Split(receiver, ";") diff --git a/model/option.go b/model/option.go index 1053f636..391fad0a 100644 --- a/model/option.go +++ b/model/option.go @@ -33,6 +33,7 @@ func InitOptionMap() { common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled) common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled) common.OptionMap["SMTPServer"] = "" + common.OptionMap["SMTPFrom"] = "" common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort) common.OptionMap["SMTPAccount"] = "" common.OptionMap["SMTPToken"] = "" @@ -58,6 +59,9 @@ func InitOptionMap() { common.SysError("Failed to update option map: " + err.Error()) } } + if common.SMTPFrom == "" { // for compatibility + common.SMTPFrom = common.SMTPAccount + } } func UpdateOption(key string, value string) error { @@ -120,6 +124,8 @@ func updateOptionMap(key string, value string) (err error) { common.SMTPPort = intValue case "SMTPAccount": common.SMTPAccount = value + case "SMTPFrom": + common.SMTPFrom = value case "SMTPToken": common.SMTPToken = value case "ServerAddress": diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index eb3193c4..b7c2a6e8 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -14,6 +14,7 @@ const SystemSetting = () => { SMTPServer: '', SMTPPort: '', SMTPAccount: '', + SMTPFrom: '', SMTPToken: '', ServerAddress: '', Footer: '', @@ -129,6 +130,9 @@ const SystemSetting = () => { if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) { await updateOption('SMTPAccount', inputs.SMTPAccount); } + if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) { + await updateOption('SMTPFrom', inputs.SMTPFrom); + } if ( originInputs['SMTPPort'] !== inputs.SMTPPort && inputs.SMTPPort !== '' @@ -298,7 +302,7 @@ const SystemSetting = () => { 配置 SMTP 用以支持系统的邮件发送 - + { value={inputs.SMTPAccount} placeholder='通常是邮箱地址' /> + + +