Skip to content

Commit

Permalink
fix email parse error in some client
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunop committed Oct 20, 2023
1 parent cfbbff9 commit 6fa63a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 4 additions & 4 deletions config/dev-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ level = "debug"
sender = "xxxxx"
secret = "xxxxx"

[cos]
secret_id="xxx"
secret_key="xxx"

[oauth.server]
# urlExample := "postgres://username:password@localhost:5432/database_name"
db_uri = "xxxx"
Expand All @@ -37,7 +41,3 @@ redirect_url = "xxx"
id = "xxx"
secret = "xxx"
redirect_url = "xxx"

[cos]
secret_id="xxx"
secret_key="xxx"
7 changes: 4 additions & 3 deletions model/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ func TestGenerateCode(t *testing.T) {
}

func TestSendEmail(t *testing.T) {
testEmail := "[email protected]"
testEmail := "[email protected]"
code := GenerateVerifyCode()
title := "发送邮件测试"
SendEmail(testEmail, code, title)
title := "发送邮件测试,请勿回复"
content := InsertCode(code)
SendEmail(testEmail, content, title)
}

func TestVerifyCode(t *testing.T) {
Expand Down
16 changes: 11 additions & 5 deletions util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"github.com/NJUPT-SAST/sast-link-backend/config"
"github.com/tencentyun/cos-go-sdk-v5"
mr "math/rand"
"net"
"net/http"
Expand All @@ -18,13 +16,20 @@ import (
"os"
"time"

"github.com/NJUPT-SAST/sast-link-backend/config"
"github.com/tencentyun/cos-go-sdk-v5"

"github.com/google/uuid"
)

var (
T_cos *cos.Client = connectToTencentCOS()
)

const (
larkSmtpServer = "smtp.feishu.cn:465"
)

func connectToTencentCOS() *cos.Client {
// 将 examplebucket-1250000000 和 COS_REGION 修改为用户真实的信息
// 存储桶名称,由 bucketname-appid 组成,appid 必须填入,可以在 COS 控制台查看存储桶名称。https://console.cloud.tencent.com/cos5/bucket
Expand Down Expand Up @@ -103,7 +108,7 @@ func GenerateCode() string {
}

// sendEmail send email to user
func SendEmail(sender string, secret string, recipient string, content, title string) error {
func SendEmail(sender, secret, recipient, content, title string) error {
// https://gist.github.com/chrisgillis/10888032
from := mail.Address{"", sender}
to := mail.Address{"", recipient}
Expand All @@ -121,10 +126,11 @@ func SendEmail(sender string, secret string, recipient string, content, title st
for k, v := range headers {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + body
header := "Content-Type: text/html; charset=\"UTF-8\";\n\n"
message += header + "\r\n" + body

// Connect to the SMTP server
servername := "smtp.feishu.cn:465"
servername := larkSmtpServer

host, _, _ := net.SplitHostPort(servername)

Expand Down

0 comments on commit 6fa63a8

Please sign in to comment.