From 7ad686937ce92a6922cb94be72def6a2522f01d2 Mon Sep 17 00:00:00 2001 From: Aine Date: Tue, 20 Feb 2024 19:53:39 +0200 Subject: [PATCH] do not report smtp "connection reset by peer" error (use warn instead) --- smtp/manager.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/smtp/manager.go b/smtp/manager.go index 87e8609..0d36581 100644 --- a/smtp/manager.go +++ b/smtp/manager.go @@ -3,7 +3,9 @@ package smtp import ( "context" "crypto/tls" + "fmt" "net" + "strings" "sync" "time" @@ -90,7 +92,14 @@ func NewManager(cfg *Config) *Manager { } s := smtp.NewServer(mailsrv) - s.ErrorLog = loggerWrapper{func(s string, i ...any) { cfg.Logger.Error().Msgf(s, i...) }} + s.ErrorLog = loggerWrapper{func(s string, i ...any) { + msg := fmt.Sprintf(s, i...) + if strings.Contains(msg, "connection reset by peer") { + cfg.Logger.Warn().Msg(msg) + return + } + cfg.Logger.Error().Msg(msg) + }} s.ReadTimeout = 10 * time.Second s.WriteTimeout = 10 * time.Second s.MaxMessageBytes = int64(cfg.MaxSize * 1024 * 1024)