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.
This commit is contained in:
Winni Neessen 2024-11-14 10:17:18 +01:00
parent a5ac7c3370
commit c8d7cf86e1
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -27,8 +27,13 @@ import (
// Returns: // Returns:
// - An error that aggregates any SendErrors encountered during the sending process; otherwise, returns nil. // - An error that aggregates any SendErrors encountered during the sending process; otherwise, returns nil.
func (c *Client) Send(messages ...*Msg) (returnErr error) { 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 { 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 return
} }