fix: close smtp client connection
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Markus Pesch 2022-07-26 13:29:21 +02:00
parent 44e9c0ad5d
commit 953497a1fe
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -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)