From 953497a1fe8f3128a9551af637159a624aa7ae10 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Tue, 26 Jul 2022 13:29:21 +0200 Subject: [PATCH] fix: close smtp client connection --- pkg/mail/mail.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/mail/mail.go b/pkg/mail/mail.go index e4d12af..4e7212b 100644 --- a/pkg/mail/mail.go +++ b/pkg/mail/mail.go @@ -165,6 +165,14 @@ func (p *Plugin) sendMail(recipient string, r io.Reader) error { return fmt.Errorf("failed to copy input from passed reader to smtp writer: %w", err) } + // close smtpClient before defer to avoid returning an error of + // smtpClient.Quit() like the following example: + // Error: failed to execute mail plugin: failed to send mail: failed to send quit command: 250 2.0.0 Ok: queued as C7F009B4ED + err = wc.Close() + if err != nil { + return fmt.Errorf("failed to close smtp client connection: %w", err) + } + err = smtpClient.Quit() if err != nil { return fmt.Errorf("failed to send quit command: %w", err)