From 3e504e6338495d0cdbfed401642b193909d5668a Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 22 Nov 2024 15:29:31 +0100 Subject: [PATCH] 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. --- client_120.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client_120.go b/client_120.go index 16e2d0b..bc157a9 100644 --- a/client_120.go +++ b/client_120.go @@ -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...) }