From 2a3e8f844f8ba3209169d7ac375425c18ce3afd0 Mon Sep 17 00:00:00 2001 From: jinnrry <19919556+Jinnrry@users.noreply.github.com> Date: Sat, 25 May 2024 23:15:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D139=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E5=8F=91=E4=BB=B6=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/go.mod | 2 +- server/utils/send/send.go | 3 ++- server/utils/smtp/smtp.go | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/go.mod b/server/go.mod index ffe9c9e..4673256 100644 --- a/server/go.mod +++ b/server/go.mod @@ -19,6 +19,7 @@ require ( golang.org/x/crypto v0.22.0 golang.org/x/text v0.14.0 modernc.org/sqlite v1.29.6 + xorm.io/builder v0.3.13 xorm.io/xorm v1.3.9 ) @@ -50,5 +51,4 @@ require ( modernc.org/memory v1.8.0 // indirect modernc.org/strutil v1.2.0 // indirect modernc.org/token v1.1.0 // indirect - xorm.io/builder v0.3.13 // indirect ) diff --git a/server/utils/send/send.go b/server/utils/send/send.go index 678101c..ee156d0 100644 --- a/server/utils/send/send.go +++ b/server/utils/send/send.go @@ -174,7 +174,8 @@ func Send(ctx *context.Context, e *parsemail.Email) (error, map[string]error) { // 使用其他方式发送 if err != nil { - if errors.Is(err, smtp.NoSupportSTARTTLSError) { + // EOF 表示未知错误,此时降级为非tls连接发送(目前仅139邮箱有这个问题) + if errors.Is(err, smtp.NoSupportSTARTTLSError) || err.Error() == "EOF" { err = smtp.SendMailWithTls("", domain.mxHost+":465", nil, e.From.EmailAddress, buildAddress(tos), b) if err != nil { log.WithContext(ctx).Warnf("Unsafe! %s Server Not Support SMTPS & STARTTLS", domain.domain) diff --git a/server/utils/smtp/smtp.go b/server/utils/smtp/smtp.go index b248097..36a9a6d 100644 --- a/server/utils/smtp/smtp.go +++ b/server/utils/smtp/smtp.go @@ -34,6 +34,7 @@ import ( ) var NoSupportSTARTTLSError = errors.New("smtp: server doesn't support STARTTLS") +var EOFError = errors.New("EOF") // A Client represents a client connection to an SMTP server. type Client struct {