From a1ce16bd5e725e8e76e6ac839537739c9eb66117 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 19 Aug 2025 09:43:23 +0800 Subject: [PATCH] fix(smtp): SMTP reset error should be ignored for non-standard SMTP server implementation (#2791) --- assets | 2 +- pkg/email/smtp.go | 11 +++++++++++ service/admin/tools.go | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/assets b/assets index f7aa0a0..2c5b89c 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit f7aa0a09e22792eeeae574b585a499f0f459cede +Subproject commit 2c5b89c59cd69a7690938f4a980468006b49b547 diff --git a/pkg/email/smtp.go b/pkg/email/smtp.go index b9ce863..ebb5c74 100644 --- a/pkg/email/smtp.go +++ b/pkg/email/smtp.go @@ -2,6 +2,7 @@ package email import ( "context" + "errors" "fmt" "strings" "time" @@ -159,6 +160,16 @@ func (client *SMTPPool) Init() { l := client.l.CopyWithPrefix(fmt.Sprintf("[Cid: %s]", m.cid)) if err := d.Send(m.msg); err != nil { + // Check if this is an SMTP RESET error after successful delivery + var sendErr *mail.SendError + var errParsed = errors.As(err, &sendErr) + if errParsed && sendErr.Reason == mail.ErrSMTPReset { + open = false + l.Debug("SMTP RESET error, closing connection...") + // https://github.com/wneessen/go-mail/issues/463 + continue // Don't treat this as a delivery failure since mail was sent + } + l.Warning("Failed to send email: %s, Cid=%s", err, m.cid) } else { l.Info("Email sent to %q, title: %q.", m.to, m.subject) diff --git a/service/admin/tools.go b/service/admin/tools.go index e13e3a7..ac701b4 100644 --- a/service/admin/tools.go +++ b/service/admin/tools.go @@ -2,6 +2,7 @@ package admin import ( "encoding/hex" + "errors" "net/http" "strconv" @@ -165,6 +166,13 @@ func (s *TestSMTPService) Test(c *gin.Context) error { err = d.DialAndSendWithContext(c, m) if err != nil { + // Check if this is an SMTP RESET error after successful delivery + var sendErr *mail.SendError + var errParsed = errors.As(err, &sendErr) + if errParsed && sendErr.Reason == mail.ErrSMTPReset { + return nil // Don't treat this as a delivery failure since mail was sent + } + return serializer.NewError(serializer.CodeInternalSetting, "Failed to send test email: "+err.Error(), err) }