diff --git a/senderror.go b/senderror.go index a371c6e..93ab6f2 100644 --- a/senderror.go +++ b/senderror.go @@ -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