mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Winni Neessen
3871b2be44
Add mutex locking for client connections to ensure thread safety. Introduce `HasConnection` method to check active connections and `UpdateDeadline` method to handle timeout updates. Refactor connection handling in `checkConn` and `tls` methods accordingly.
36 lines
705 B
Go
36 lines
705 B
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) (returnErr error) {
|
|
c.mutex.Lock()
|
|
defer c.mutex.Unlock()
|
|
if err := c.checkConn(); err != nil {
|
|
returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)}
|
|
return
|
|
}
|
|
|
|
var errs []error
|
|
defer func() {
|
|
returnErr = errors.Join(errs...)
|
|
}()
|
|
|
|
for id, message := range messages {
|
|
if sendErr := c.sendSingleMsg(message); sendErr != nil {
|
|
messages[id].sendError = sendErr
|
|
errs = append(errs, sendErr)
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|