From 32cd890b6e079282205ad9dc47619243dc5ecae1 Mon Sep 17 00:00:00 2001 From: han shi Date: Fri, 25 Apr 2025 18:17:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0sendcloud=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20(#947)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加sendcloud邮件服务器的支持 * 调整代码结构 * Used slince.Contains function --------- Co-authored-by: shih --- common/constants.go | 4 ++++ common/email.go | 3 ++- common/utils.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/constants.go b/common/constants.go index ed50fae6..dd4f3b04 100644 --- a/common/constants.go +++ b/common/constants.go @@ -62,6 +62,10 @@ var EmailDomainWhitelist = []string{ "yahoo.com", "foxmail.com", } +var EmailLoginAuthServerList = []string{ + "smtp.sendcloud.net", + "smtp.azurecomm.net", +} var DebugEnabled bool var MemoryCacheEnabled bool diff --git a/common/email.go b/common/email.go index 8eb575f3..18e6dbf7 100644 --- a/common/email.go +++ b/common/email.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "fmt" "net/smtp" + "slices" "strings" "time" ) @@ -79,7 +80,7 @@ func SendEmail(subject string, receiver string, content string) error { if err != nil { return err } - } else if isOutlookServer(SMTPAccount) || SMTPServer == "smtp.azurecomm.net" { + } else if isOutlookServer(SMTPAccount) || slices.Contains(EmailLoginAuthServerList, SMTPServer) { auth = LoginAuth(SMTPAccount, SMTPToken) err = smtp.SendMail(addr, auth, SMTPFrom, to, mail) } else { diff --git a/common/utils.go b/common/utils.go index e57801e3..587de537 100644 --- a/common/utils.go +++ b/common/utils.go @@ -7,7 +7,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/pkg/errors" "html/template" "io" "log" @@ -22,6 +21,7 @@ import ( "time" "github.com/google/uuid" + "github.com/pkg/errors" ) func OpenBrowser(url string) {