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
c709ab7c
authored
Dec 04, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: email panic
parent
d7f4ea06
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
common/email.go
+11
-3
No files found.
common/email.go
View file @
c709ab7c
...
@@ -9,12 +9,20 @@ import (
...
@@ -9,12 +9,20 @@ import (
"time"
"time"
)
)
func
generateMessageID
()
string
{
func
generateMessageID
()
(
string
,
error
)
{
split
:=
strings
.
Split
(
SMTPAccount
,
"@"
)
if
len
(
split
)
<
2
{
return
""
,
fmt
.
Errorf
(
"invalid SMTP account"
)
}
domain
:=
strings
.
Split
(
SMTPAccount
,
"@"
)[
1
]
domain
:=
strings
.
Split
(
SMTPAccount
,
"@"
)[
1
]
return
fmt
.
Sprintf
(
"<%d.%s@%s>"
,
time
.
Now
()
.
UnixNano
(),
GetRandomString
(
12
),
domain
)
return
fmt
.
Sprintf
(
"<%d.%s@%s>"
,
time
.
Now
()
.
UnixNano
(),
GetRandomString
(
12
),
domain
)
,
nil
}
}
func
SendEmail
(
subject
string
,
receiver
string
,
content
string
)
error
{
func
SendEmail
(
subject
string
,
receiver
string
,
content
string
)
error
{
id
,
err2
:=
generateMessageID
()
if
err2
!=
nil
{
return
err2
}
if
SMTPFrom
==
""
{
// for compatibility
if
SMTPFrom
==
""
{
// for compatibility
SMTPFrom
=
SMTPAccount
SMTPFrom
=
SMTPAccount
}
}
...
@@ -28,7 +36,7 @@ func SendEmail(subject string, receiver string, content string) error {
...
@@ -28,7 +36,7 @@ func SendEmail(subject string, receiver string, content string) error {
"Date: %s
\r\n
"
+
"Date: %s
\r\n
"
+
"Message-ID: %s
\r\n
"
+
// 添加 Message-ID 头
"Message-ID: %s
\r\n
"
+
// 添加 Message-ID 头
"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
,
SMTPFrom
,
encodedSubject
,
time
.
Now
()
.
Format
(
time
.
RFC1123Z
),
generateMessageID
()
,
content
))
receiver
,
SystemName
,
SMTPFrom
,
encodedSubject
,
time
.
Now
()
.
Format
(
time
.
RFC1123Z
),
id
,
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
,
";"
)
...
...
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