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
badbb096
authored
May 13, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use built in smtp library (close #34)
parent
9ed9eaa6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
common/email.go
+14
-8
go.mod
+1
-4
go.sum
+0
-0
No files found.
common/email.go
View file @
badbb096
package
common
import
"gopkg.in/gomail.v2"
import
(
"fmt"
"net/smtp"
"strings"
)
func
SendEmail
(
subject
string
,
receiver
string
,
content
string
)
error
{
m
:=
gomail
.
NewMessage
()
m
.
SetHeader
(
"From"
,
SMTPAccount
)
m
.
SetHeader
(
"To"
,
receiver
)
m
.
SetHeader
(
"Subject"
,
subject
)
m
.
SetBody
(
"text/html"
,
content
)
d
:=
gomail
.
NewDialer
(
SMTPServer
,
SMTPPort
,
SMTPAccount
,
SMTPToken
)
err
:=
d
.
DialAndSend
(
m
)
mail
:=
[]
byte
(
fmt
.
Sprintf
(
"To: %s
\r\n
"
+
"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
))
auth
:=
smtp
.
PlainAuth
(
""
,
SMTPAccount
,
SMTPToken
,
SMTPServer
)
addr
:=
fmt
.
Sprintf
(
"%s:%d"
,
SMTPServer
,
SMTPPort
)
to
:=
strings
.
Split
(
receiver
,
";"
)
err
:=
smtp
.
SendMail
(
addr
,
auth
,
SMTPAccount
,
to
,
mail
)
return
err
}
go.mod
View file @
badbb096
...
...
@@ -12,8 +12,8 @@ require (
github.com/go-playground/validator/v10 v10.12.0
github.com/go-redis/redis/v8 v8.11.5
github.com/google/uuid v1.3.0
github.com/pkoukk/tiktoken-go v0.1.1
golang.org/x/crypto v0.8.0
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gorm.io/driver/mysql v1.4.3
gorm.io/driver/sqlite v1.4.3
gorm.io/gorm v1.24.0
...
...
@@ -45,7 +45,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pkoukk/tiktoken-go v0.1.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
...
...
@@ -53,7 +52,5 @@ require (
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
go.sum
View file @
badbb096
This diff is collapsed.
Click to expand it.
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