From 5aebb12241f46ec57b8a4d20aa7cda5f10853108 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 11 Mar 2022 19:17:43 +0100 Subject: [PATCH] Calling it a day... --- client.go | 15 +++++++++++++++ cmd/main.go | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/client.go b/client.go index 0df492c..249f74f 100644 --- a/client.go +++ b/client.go @@ -295,6 +295,18 @@ func (c *Client) Close() error { return nil } +// Reset sends the RSET command to the SMTP client +func (c *Client) Reset() error { + if err := c.checkConn(); err != nil { + return err + } + if err := c.sc.Reset(); err != nil { + return fmt.Errorf("failed to send RSET to SMTP client: %w", err) + } + + return nil +} + // DialAndSend establishes a connection to the SMTP server with a // default context.Background and sends the mail func (c *Client) DialAndSend() error { @@ -314,6 +326,9 @@ func (c *Client) checkConn() error { if c.co == nil { return ErrNoActiveConnection } + if err := c.sc.Noop(); err != nil { + return ErrNoActiveConnection + } if err := c.co.SetDeadline(time.Now().Add(c.cto)); err != nil { return ErrDeadlineExtendFailed } diff --git a/cmd/main.go b/cmd/main.go index 897ae16..8a0b2c5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -41,6 +41,10 @@ func main() { os.Exit(1) } defer func() { + if err := c.Reset(); err != nil { + fmt.Printf("failed to reset: %s\n", err) + os.Exit(1) + } if err := c.Close(); err != nil { fmt.Printf("failed to close: %s\n", err) os.Exit(1)