diff --git a/common/constants.go b/common/constants.go index a54ca7a..54dcf77 100644 --- a/common/constants.go +++ b/common/constants.go @@ -33,6 +33,7 @@ var MessagePersistenceEnabled = true var MessageRenderEnabled = true var SMTPServer = "" +var SMTPPort = 587 var SMTPAccount = "" var SMTPToken = "" diff --git a/common/email.go b/common/email.go index 8e293be..1f0ad7e 100644 --- a/common/email.go +++ b/common/email.go @@ -8,7 +8,7 @@ func SendEmail(subject string, receiver string, content string) error { m.SetHeader("To", receiver) m.SetHeader("Subject", subject) m.SetBody("text/html", content) - d := gomail.NewDialer(SMTPServer, 587, SMTPAccount, SMTPToken) + d := gomail.NewDialer(SMTPServer, SMTPPort, SMTPAccount, SMTPToken) err := d.DialAndSend(m) return err } diff --git a/model/option.go b/model/option.go index b430845..1146196 100644 --- a/model/option.go +++ b/model/option.go @@ -36,6 +36,7 @@ func InitOptionMap() { common.OptionMap["MessageRenderEnabled"] = strconv.FormatBool(common.MessageRenderEnabled) common.OptionMap["SMTPServer"] = "" common.OptionMap["SMTPAccount"] = "" + common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort) common.OptionMap["SMTPToken"] = "" common.OptionMap["Notice"] = "" common.OptionMap["About"] = "" @@ -114,6 +115,9 @@ func updateOptionMap(key string, value string) { switch key { case "SMTPServer": common.SMTPServer = value + case "SMTPPort": + intValue, _ := strconv.Atoi(value) + common.SMTPPort = intValue case "SMTPAccount": common.SMTPAccount = value case "SMTPToken": diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index 7fc0179..442f466 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -12,6 +12,7 @@ const SystemSetting = () => { GitHubClientSecret: '', Notice: '', SMTPServer: '', + SMTPPort: '', SMTPAccount: '', SMTPToken: '', ServerAddress: '', @@ -110,6 +111,12 @@ const SystemSetting = () => { if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) { await updateOption('SMTPAccount', inputs.SMTPAccount); } + if ( + originInputs['SMTPPort'] !== inputs.SMTPPort && + inputs.SMTPPort !== '' + ) { + await updateOption('SMTPPort', inputs.SMTPPort); + } if ( originInputs['SMTPToken'] !== inputs.SMTPToken && inputs.SMTPToken !== '' @@ -259,6 +266,14 @@ const SystemSetting = () => { value={inputs.SMTPServer} placeholder='例如:smtp.qq.com' /> +