From 484a8595e4558e4e5f2879367f2598e47e1e18a7 Mon Sep 17 00:00:00 2001 From: OswinWu Date: Fri, 23 Aug 2024 17:16:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=9A=E5=9C=B0=E5=8C=BAoutlook?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E5=92=8Cofb=E9=82=AE=E7=AE=B1Auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/email-outlook-auth.go | 8 ++++++++ common/email.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/email-outlook-auth.go b/common/email-outlook-auth.go index 723a10b..f6a71b8 100644 --- a/common/email-outlook-auth.go +++ b/common/email-outlook-auth.go @@ -3,6 +3,7 @@ package common import ( "errors" "net/smtp" + "strings" ) type outlookAuth struct { @@ -30,3 +31,10 @@ func (a *outlookAuth) Next(fromServer []byte, more bool) ([]byte, error) { } return nil, nil } + +func isOutlookServer(server string) bool { + // 兼容多地区的outlook邮箱和ofb邮箱 + // 其实应该加一个Option来区分是否用LOGIN的方式登录 + // 先临时兼容一下 + return strings.Contains(server, "outlook") || strings.Contains(server, "onmicrosoft") +} diff --git a/common/email.go b/common/email.go index b23bb23..905f385 100644 --- a/common/email.go +++ b/common/email.go @@ -68,7 +68,7 @@ func SendEmail(subject string, receiver string, content string) error { if err != nil { return err } - } else if strings.HasSuffix(SMTPAccount, "outlook.com") { + } else if isOutlookServer(SMTPAccount) { auth = LoginAuth(SMTPAccount, SMTPToken) err = smtp.SendMail(addr, auth, SMTPAccount, to, mail) } else {