Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6cb284c8
authored
May 13, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: able to configure smtp from now (close #34)
parent
bc87b023
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
2 deletions
+23
-2
common/constants.go
+1
-0
common/email.go
+1
-1
model/option.go
+6
-0
web/src/components/SystemSetting.js
+15
-1
No files found.
common/constants.go
View file @
6cb284c8
...
@@ -36,6 +36,7 @@ var RegisterEnabled = true
...
@@ -36,6 +36,7 @@ var RegisterEnabled = true
var
SMTPServer
=
""
var
SMTPServer
=
""
var
SMTPPort
=
587
var
SMTPPort
=
587
var
SMTPAccount
=
""
var
SMTPAccount
=
""
var
SMTPFrom
=
""
var
SMTPToken
=
""
var
SMTPToken
=
""
var
GitHubClientId
=
""
var
GitHubClientId
=
""
...
...
common/email.go
View file @
6cb284c8
...
@@ -11,7 +11,7 @@ func SendEmail(subject string, receiver string, content string) error {
...
@@ -11,7 +11,7 @@ func SendEmail(subject string, receiver string, content string) error {
"From: %s<%s>
\r\n
"
+
"From: %s<%s>
\r\n
"
+
"Subject: %s
\r\n
"
+
"Subject: %s
\r\n
"
+
"Content-Type: text/html; charset=UTF-8
\r\n\r\n
%s
\r\n
"
,
"Content-Type: text/html; charset=UTF-8
\r\n\r\n
%s
\r\n
"
,
receiver
,
SystemName
,
SMTP
Account
,
subject
,
content
))
receiver
,
SystemName
,
SMTP
From
,
subject
,
content
))
auth
:=
smtp
.
PlainAuth
(
""
,
SMTPAccount
,
SMTPToken
,
SMTPServer
)
auth
:=
smtp
.
PlainAuth
(
""
,
SMTPAccount
,
SMTPToken
,
SMTPServer
)
addr
:=
fmt
.
Sprintf
(
"%s:%d"
,
SMTPServer
,
SMTPPort
)
addr
:=
fmt
.
Sprintf
(
"%s:%d"
,
SMTPServer
,
SMTPPort
)
to
:=
strings
.
Split
(
receiver
,
";"
)
to
:=
strings
.
Split
(
receiver
,
";"
)
...
...
model/option.go
View file @
6cb284c8
...
@@ -33,6 +33,7 @@ func InitOptionMap() {
...
@@ -33,6 +33,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"TurnstileCheckEnabled"
]
=
strconv
.
FormatBool
(
common
.
TurnstileCheckEnabled
)
common
.
OptionMap
[
"TurnstileCheckEnabled"
]
=
strconv
.
FormatBool
(
common
.
TurnstileCheckEnabled
)
common
.
OptionMap
[
"RegisterEnabled"
]
=
strconv
.
FormatBool
(
common
.
RegisterEnabled
)
common
.
OptionMap
[
"RegisterEnabled"
]
=
strconv
.
FormatBool
(
common
.
RegisterEnabled
)
common
.
OptionMap
[
"SMTPServer"
]
=
""
common
.
OptionMap
[
"SMTPServer"
]
=
""
common
.
OptionMap
[
"SMTPFrom"
]
=
""
common
.
OptionMap
[
"SMTPPort"
]
=
strconv
.
Itoa
(
common
.
SMTPPort
)
common
.
OptionMap
[
"SMTPPort"
]
=
strconv
.
Itoa
(
common
.
SMTPPort
)
common
.
OptionMap
[
"SMTPAccount"
]
=
""
common
.
OptionMap
[
"SMTPAccount"
]
=
""
common
.
OptionMap
[
"SMTPToken"
]
=
""
common
.
OptionMap
[
"SMTPToken"
]
=
""
...
@@ -58,6 +59,9 @@ func InitOptionMap() {
...
@@ -58,6 +59,9 @@ func InitOptionMap() {
common
.
SysError
(
"Failed to update option map: "
+
err
.
Error
())
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
{
func
UpdateOption
(
key
string
,
value
string
)
error
{
...
@@ -120,6 +124,8 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -120,6 +124,8 @@ func updateOptionMap(key string, value string) (err error) {
common
.
SMTPPort
=
intValue
common
.
SMTPPort
=
intValue
case
"SMTPAccount"
:
case
"SMTPAccount"
:
common
.
SMTPAccount
=
value
common
.
SMTPAccount
=
value
case
"SMTPFrom"
:
common
.
SMTPFrom
=
value
case
"SMTPToken"
:
case
"SMTPToken"
:
common
.
SMTPToken
=
value
common
.
SMTPToken
=
value
case
"ServerAddress"
:
case
"ServerAddress"
:
...
...
web/src/components/SystemSetting.js
View file @
6cb284c8
...
@@ -14,6 +14,7 @@ const SystemSetting = () => {
...
@@ -14,6 +14,7 @@ const SystemSetting = () => {
SMTPServer
:
''
,
SMTPServer
:
''
,
SMTPPort
:
''
,
SMTPPort
:
''
,
SMTPAccount
:
''
,
SMTPAccount
:
''
,
SMTPFrom
:
''
,
SMTPToken
:
''
,
SMTPToken
:
''
,
ServerAddress
:
''
,
ServerAddress
:
''
,
Footer
:
''
,
Footer
:
''
,
...
@@ -129,6 +130,9 @@ const SystemSetting = () => {
...
@@ -129,6 +130,9 @@ const SystemSetting = () => {
if
(
originInputs
[
'SMTPAccount'
]
!==
inputs
.
SMTPAccount
)
{
if
(
originInputs
[
'SMTPAccount'
]
!==
inputs
.
SMTPAccount
)
{
await
updateOption
(
'SMTPAccount'
,
inputs
.
SMTPAccount
);
await
updateOption
(
'SMTPAccount'
,
inputs
.
SMTPAccount
);
}
}
if
(
originInputs
[
'SMTPFrom'
]
!==
inputs
.
SMTPFrom
)
{
await
updateOption
(
'SMTPFrom'
,
inputs
.
SMTPFrom
);
}
if
(
if
(
originInputs
[
'SMTPPort'
]
!==
inputs
.
SMTPPort
&&
originInputs
[
'SMTPPort'
]
!==
inputs
.
SMTPPort
&&
inputs
.
SMTPPort
!==
''
inputs
.
SMTPPort
!==
''
...
@@ -298,7 +302,7 @@ const SystemSetting = () => {
...
@@ -298,7 +302,7 @@ const SystemSetting = () => {
配置
SMTP
配置
SMTP
<
Header
.
Subheader
>
用以支持系统的邮件发送
<
/Header.Subheader
>
<
Header
.
Subheader
>
用以支持系统的邮件发送
<
/Header.Subheader
>
<
/Header
>
<
/Header
>
<
Form
.
Group
widths
=
{
4
}
>
<
Form
.
Group
widths
=
{
3
}
>
<
Form
.
Input
<
Form
.
Input
label
=
'SMTP 服务器地址'
label
=
'SMTP 服务器地址'
name
=
'SMTPServer'
name
=
'SMTPServer'
...
@@ -323,6 +327,16 @@ const SystemSetting = () => {
...
@@ -323,6 +327,16 @@ const SystemSetting = () => {
value
=
{
inputs
.
SMTPAccount
}
value
=
{
inputs
.
SMTPAccount
}
placeholder
=
'通常是邮箱地址'
placeholder
=
'通常是邮箱地址'
/>
/>
<
/Form.Group
>
<
Form
.
Group
widths
=
{
3
}
>
<
Form
.
Input
label
=
'SMTP 发送者邮箱'
name
=
'SMTPFrom'
onChange
=
{
handleInputChange
}
autoComplete
=
'new-password'
value
=
{
inputs
.
SMTPFrom
}
placeholder
=
'通常和邮箱地址保持一致'
/>
<
Form
.
Input
<
Form
.
Input
label
=
'SMTP 访问凭证'
label
=
'SMTP 访问凭证'
name
=
'SMTPToken'
name
=
'SMTPToken'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment