diff --git a/client.go b/client.go index 637e299..4ee68f0 100644 --- a/client.go +++ b/client.go @@ -1108,6 +1108,12 @@ func (c *Client) DialAndSendWithContext(ctx context.Context, messages ...*Msg) e return nil } +func (c *Client) Send(messages ...*Msg) (returnErr error) { + c.sendMutex.Lock() + defer c.sendMutex.Unlock() + return c.SendWithSMTPClient(c.smtpClient, messages...) +} + // auth attempts to authenticate the client using SMTP AUTH mechanisms. It checks the connection, // determines the supported authentication methods, and applies the appropriate authentication // type. An error is returned if authentication fails. diff --git a/client_119.go b/client_119.go index a28f747..fb8c982 100644 --- a/client_119.go +++ b/client_119.go @@ -7,7 +7,11 @@ package mail -import "errors" +import ( + "errors" + + "github.com/wneessen/go-mail/smtp" +) // Send attempts to send one or more Msg using the Client connection to the SMTP server. // If the Client has no active connection to the server, Send will fail with an error. For each @@ -26,12 +30,13 @@ import "errors" // Returns: // - An error that represents the sending result, which may include multiple SendErrors if // any occurred; otherwise, returns nil. -func (c *Client) Send(messages ...*Msg) error { + +func (c *Client) SendWithSMTPClient(client *smtp.Client, messages ...*Msg) error { escSupport := false - if c.smtpClient != nil { - escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES") + if client != nil { + escSupport, _ = client.Extension("ENHANCEDSTATUSCODES") } - if err := c.checkConn(); err != nil { + if err := c.checkConn(client); err != nil { return &SendError{ Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err), errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport), @@ -39,7 +44,7 @@ func (c *Client) Send(messages ...*Msg) error { } var errs []*SendError for id, message := range messages { - if sendErr := c.sendSingleMsg(message); sendErr != nil { + if sendErr := c.sendSingleMsg(client, message); sendErr != nil { messages[id].sendError = sendErr var msgSendErr *SendError diff --git a/client_120.go b/client_120.go index bc157a9..e9ce8dc 100644 --- a/client_120.go +++ b/client_120.go @@ -28,11 +28,6 @@ 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...) -} func (c *Client) SendWithSMTPClient(client *smtp.Client, messages ...*Msg) (returnErr error) { escSupport := false