mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Winni Neessen
253d065c83
Mutex locking was relocated from the Send method in client_120.go and client_119.go to sendSingleMsg in client.go. This ensures thread-safety specifically during the message transmission process.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !go1.20
|
|
// +build !go1.20
|
|
|
|
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 id, message := range messages {
|
|
if sendErr := c.sendSingleMsg(message); sendErr != nil {
|
|
messages[id].sendError = sendErr
|
|
|
|
var msgSendErr *SendError
|
|
if errors.As(sendErr, &msgSendErr) {
|
|
errs = append(errs, msgSendErr)
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
if len(errs) > 1 {
|
|
returnErr := &SendError{Reason: ErrAmbiguous}
|
|
for i := range errs {
|
|
returnErr.errlist = append(returnErr.errlist, errs[i].errlist...)
|
|
returnErr.rcpt = append(returnErr.rcpt, errs[i].rcpt...)
|
|
}
|
|
|
|
// We assume that the isTemp flag from the last error we received should be the
|
|
// indicator for the returned isTemp flag as well
|
|
returnErr.isTemp = errs[len(errs)-1].isTemp
|
|
|
|
return returnErr
|
|
}
|
|
return errs[0]
|
|
}
|
|
return nil
|
|
}
|