2023-01-15 16:14:19 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
2022-12-10 13:41:00 +01:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
//go:build !go1.20
|
|
|
|
// +build !go1.20
|
|
|
|
|
|
|
|
package mail
|
|
|
|
|
|
|
|
// Send sends out the mail message
|
2024-02-27 11:10:49 +01:00
|
|
|
func (c *Client) Send(messages ...*Msg) error {
|
2023-01-02 12:14:14 +01:00
|
|
|
if cerr := c.checkConn(); cerr != nil {
|
|
|
|
return &SendError{Reason: ErrConnCheck, errlist: []error{cerr}, isTemp: isTempError(cerr)}
|
2022-12-10 13:41:00 +01:00
|
|
|
}
|
2023-01-02 12:14:14 +01:00
|
|
|
var errs []*SendError
|
2024-02-27 11:10:49 +01:00
|
|
|
for _, message := range messages {
|
2024-09-19 10:56:01 +02:00
|
|
|
if sendErr := c.sendSingleMsg(message); sendErr != nil {
|
|
|
|
messages[id].sendError = sendErr
|
2024-02-27 11:10:49 +01:00
|
|
|
errs = append(errs, sendErr)
|
2022-12-10 13:41:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(errs) > 0 {
|
2023-01-02 12:14:14 +01:00
|
|
|
if len(errs) > 1 {
|
2024-02-27 11:10:49 +01:00
|
|
|
returnErr := &SendError{Reason: ErrAmbiguous}
|
2023-01-02 12:14:14 +01:00
|
|
|
for i := range errs {
|
2024-02-27 11:10:49 +01:00
|
|
|
returnErr.errlist = append(returnErr.errlist, errs[i].errlist...)
|
|
|
|
returnErr.rcpt = append(returnErr.rcpt, errs[i].rcpt...)
|
2022-12-10 13:41:00 +01:00
|
|
|
}
|
2023-01-02 12:14:14 +01:00
|
|
|
|
2023-01-02 22:21:23 +01:00
|
|
|
// We assume that the isTemp flag from the last error we received should be the
|
2023-01-02 12:14:14 +01:00
|
|
|
// indicator for the returned isTemp flag as well
|
2024-02-27 11:10:49 +01:00
|
|
|
returnErr.isTemp = errs[len(errs)-1].isTemp
|
2023-01-02 12:14:14 +01:00
|
|
|
|
2024-02-27 11:10:49 +01:00
|
|
|
return returnErr
|
2022-12-10 13:41:00 +01:00
|
|
|
}
|
2023-01-02 12:14:14 +01:00
|
|
|
return errs[0]
|
2022-12-10 13:41:00 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|