mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-14 18:02:55 +01:00
Refactor SMTP client comment and function documentation
Updated function comments across client.go to improve clarity and consistency. Added missing details on error handling and context usage for `DialAndSendWithContext` and ensured all functions contain relevant, detailed descriptions.
This commit is contained in:
parent
adcb8ac41d
commit
48b469faf7
1 changed files with 12 additions and 7 deletions
19
client.go
19
client.go
|
@ -715,9 +715,9 @@ func (c *Client) DialWithContext(dialCtx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Close closes the Client connection
|
||||
// Close terminates the connection to the SMTP server, returning an error if the disconnection fails.
|
||||
// If the connection is already closed, we considered this a no-op and disregard any error.
|
||||
func (c *Client) Close() error {
|
||||
// If the connection is already closed, we considered this a no-op and disregard any error.
|
||||
if !c.smtpClient.HasConnection() {
|
||||
return nil
|
||||
}
|
||||
|
@ -728,7 +728,7 @@ func (c *Client) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Reset sends the RSET command to the SMTP client
|
||||
// Reset sends an SMTP RSET command to reset the state of the current SMTP session.
|
||||
func (c *Client) Reset() error {
|
||||
if err := c.checkConn(); err != nil {
|
||||
return err
|
||||
|
@ -740,19 +740,24 @@ func (c *Client) Reset() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DialAndSend establishes a connection to the SMTP server with a
|
||||
// default context.Background and sends the mail
|
||||
// DialAndSend establishes a connection to the server and sends out the provided Msg. It will call
|
||||
// DialAndSendWithContext with an empty Context.Background
|
||||
func (c *Client) DialAndSend(messages ...*Msg) error {
|
||||
ctx := context.Background()
|
||||
return c.DialAndSendWithContext(ctx, messages...)
|
||||
}
|
||||
|
||||
// DialAndSendWithContext establishes a connection to the SMTP server with a
|
||||
// custom context and sends the mail
|
||||
// DialAndSendWithContext establishes a connection to the SMTP server using DialWithContext using the
|
||||
// provided context.Context, then sends out the given Msg. After successful delivery the Client
|
||||
// will close the connection to the server.
|
||||
func (c *Client) DialAndSendWithContext(ctx context.Context, messages ...*Msg) error {
|
||||
if err := c.DialWithContext(ctx); err != nil {
|
||||
return fmt.Errorf("dial failed: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = c.Close()
|
||||
}()
|
||||
|
||||
if err := c.Send(messages...); err != nil {
|
||||
return fmt.Errorf("send failed: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue