From c8d7cf86e14642aee524bcfd703bbaca45583208 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Thu, 14 Nov 2024 10:17:18 +0100 Subject: [PATCH] Enhance error handling in Client's Send method Added support for Enhanced Status Codes (ESC) when checking the SMTP client's extensions. The SendError struct now includes the error code and enhanced status code for improved diagnostics. --- client_120.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client_120.go b/client_120.go index 012a4f7..38eb76e 100644 --- a/client_120.go +++ b/client_120.go @@ -27,8 +27,13 @@ import ( // Returns: // - An error that aggregates any SendErrors encountered during the sending process; otherwise, returns nil. func (c *Client) Send(messages ...*Msg) (returnErr error) { + escSupport := false + if c.smtpClient != nil { + escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES") + } if err := c.checkConn(); err != nil { - returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)} + returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err), + errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport)} return }