Not that this particular part of the code is performance critical, but I figured that the `strconv.Atoi()` is actually useless in here.
Since all we want to know is if the error code from the SMTP server is a 4xx error, we can just check the first rune of the returned error. The `Atoi` provides us with no advantage over the simple rune compare (except of taking about 3ns longer to execute)
Did a complete overhaul of the senderror.go.
- the list of `errors.New()` has been replaced with constant itoa error reasons as `SendErrReason`. Instead, the `Error()` method now reports the corresponding error message based on the reason.
- The `SendError` received a `Is()` method so that we can use `errors.Is()` for very specific error checking. I.e. we can check for `&SendErrors{Reason: ErrSMTPMailFrom, isTemp: true}`. This provides much more flexibility in the error checking capabilities
- A `isTemp` field has been added to the `SendError` type, indicating whether the received error is temporary and can be retried or not. Accordingly, the `*Msg` now has a `SendErrorIsTemp()` method indicating the same. The decision is based on the first 3 characters returned from the SMTP server. If the error code is within the 4xx range, the error is seen as temporary
- A test for the SendError type has been added
This PR introduces the `SendError` type which implements the error interface.
A new `senderror` field has been added to the `Msg` as well, so introduce this type to it.
I've also added different error variables that indicate the different things that can go wrong during mail delivery. These variables can be checked for, for each `Msg` using the `errors.As` method
The `Error()` method of `SendError` will return a detailed error string on why the `Msg` could not be delivered.
Additionally, `HasSendError()` and `SendError()` methods have been added to `Msg`. While `HasSendError()` simply returns a bool in case a `Msg` failed during delivery, the `SendError()` will return the full `SendError` error interface.