Lock sendMutex to ensure thread safety in Send

Added a mutex lock and unlock around the Send function to prevent concurrent access issues and ensure thread safety. This change helps avoid race conditions when multiple goroutines attempt to send messages simultaneously.
This commit is contained in:
Winni Neessen 2024-11-22 15:29:31 +01:00
parent be4201b05a
commit 3e504e6338
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -29,6 +29,8 @@ import (
// Returns:
// - An error that aggregates any SendErrors encountered during the sending process; otherwise, returns nil.
func (c *Client) Send(messages ...*Msg) (returnErr error) {
c.sendMutex.Lock()
defer c.sendMutex.Unlock()
return c.SendWithSMTPClient(c.smtpClient, messages...)
}