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
b354af02
authored
Dec 07, 2024
by
wzxjohn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support Azure Comm Service SMTP
parent
dd2beeba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
common/email.go
+8
-8
No files found.
common/email.go
View file @
b354af02
...
...
@@ -10,22 +10,22 @@ import (
)
func
generateMessageID
()
(
string
,
error
)
{
split
:=
strings
.
Split
(
SMTP
Account
,
"@"
)
split
:=
strings
.
Split
(
SMTP
From
,
"@"
)
if
len
(
split
)
<
2
{
return
""
,
fmt
.
Errorf
(
"invalid SMTP account"
)
}
domain
:=
strings
.
Split
(
SMTP
Account
,
"@"
)[
1
]
domain
:=
strings
.
Split
(
SMTP
From
,
"@"
)[
1
]
return
fmt
.
Sprintf
(
"<%d.%s@%s>"
,
time
.
Now
()
.
UnixNano
(),
GetRandomString
(
12
),
domain
),
nil
}
func
SendEmail
(
subject
string
,
receiver
string
,
content
string
)
error
{
if
SMTPFrom
==
""
{
// for compatibility
SMTPFrom
=
SMTPAccount
}
id
,
err2
:=
generateMessageID
()
if
err2
!=
nil
{
return
err2
}
if
SMTPFrom
==
""
{
// for compatibility
SMTPFrom
=
SMTPAccount
}
if
SMTPServer
==
""
&&
SMTPAccount
==
""
{
return
fmt
.
Errorf
(
"SMTP 服务器未配置"
)
}
...
...
@@ -79,11 +79,11 @@ func SendEmail(subject string, receiver string, content string) error {
if
err
!=
nil
{
return
err
}
}
else
if
isOutlookServer
(
SMTPAccount
)
{
}
else
if
isOutlookServer
(
SMTPAccount
)
||
SMTPServer
==
"smtp.azurecomm.net"
{
auth
=
LoginAuth
(
SMTPAccount
,
SMTPToken
)
err
=
smtp
.
SendMail
(
addr
,
auth
,
SMTP
Account
,
to
,
mail
)
err
=
smtp
.
SendMail
(
addr
,
auth
,
SMTP
From
,
to
,
mail
)
}
else
{
err
=
smtp
.
SendMail
(
addr
,
auth
,
SMTP
Account
,
to
,
mail
)
err
=
smtp
.
SendMail
(
addr
,
auth
,
SMTP
From
,
to
,
mail
)
}
return
err
}
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