Fix error handling in Send method in client_119.go

Refine Send method to correctly typecast and accumulate SendError instances. Introduce "errors" package import to utilize errors.As for precise error type checking, ensuring accurate error lists. This regression was introduced with PR #301
This commit is contained in:
Winni Neessen 2024-09-20 16:40:12 +02:00
parent 8dfb121aec
commit bd5a8a40b9
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -7,16 +7,22 @@
package mail
import "errors"
// Send sends out the mail message
func (c *Client) Send(messages ...*Msg) error {
if err := c.checkConn(); err != nil {
return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)}
}
var errs []*SendError
for _, message := range messages {
for id, message := range messages {
if sendErr := c.sendSingleMsg(message); sendErr != nil {
messages[id].sendError = sendErr
errs = append(errs, sendErr)
var msgSendErr *SendError
if errors.As(sendErr, &msgSendErr) {
errs = append(errs, msgSendErr)
}
}
}