Enhance error handling with ENHANCEDSTATUSCODES check

Added a check for the ENHANCEDSTATUSCODES extension and included error code and enhanced status code information in SendError. This helps in providing more detailed error reporting and troubleshooting.
This commit is contained in:
Winni Neessen 2024-11-13 23:02:30 +01:00
parent f367db0278
commit 719e5b217c
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -27,8 +27,13 @@ import "errors"
// - An error that represents the sending result, which may include multiple SendErrors if // - An error that represents the sending result, which may include multiple SendErrors if
// any occurred; otherwise, returns nil. // any occurred; otherwise, returns nil.
func (c *Client) Send(messages ...*Msg) error { func (c *Client) Send(messages ...*Msg) error {
escSupport := false
if c.smtpClient != nil {
escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES")
}
if err := c.checkConn(); err != nil { if err := c.checkConn(); err != nil {
return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)} return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err),
errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport)}
} }
var errs []*SendError var errs []*SendError
for id, message := range messages { for id, message := range messages {