From ad265cac57670289aedacd5acc27331d7a98d1df Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 13 Nov 2024 21:26:11 +0100 Subject: [PATCH] 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. --- senderror.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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