Add ErrorCode method to SendError

Implemented ErrorCode method to retrieve the error code from the server response in SendError. This method distinguishes between server-generated errors and client-generated errors, returning 0 for errors generated by the client.
This commit is contained in:
Winni Neessen 2024-11-13 21:26:11 +01:00
parent b9d9449252
commit ad265cac57
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -200,6 +200,21 @@ func (e *SendError) EnhancedStatusCode() string {
return e.enhancedStatusCode
}
// ErrorCode returns the error code of the server response.
//
// This function retrieves the error code the error returned by the server. The error code will
// start with 5 on permanent errors and with 4 on a temporary error. If the error is not returned
// by the server, but is generated by go-mail, the code will be 0.
//
// Returns:
// - The error code as returned by the server, or 0 if not a server error.
func (e *SendError) ErrorCode() int {
if e == nil {
return 0
}
return e.errcode
}
// String satisfies the fmt.Stringer interface for the SendErrReason type.
//
// This function converts the SendErrReason into a human-readable string representation based