Calling it a day...

This commit is contained in:
Winni Neessen 2022-03-11 19:17:43 +01:00
parent 6a497d2780
commit 5aebb12241
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
2 changed files with 19 additions and 0 deletions

View file

@ -295,6 +295,18 @@ func (c *Client) Close() error {
return nil 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 // DialAndSend establishes a connection to the SMTP server with a
// default context.Background and sends the mail // default context.Background and sends the mail
func (c *Client) DialAndSend() error { func (c *Client) DialAndSend() error {
@ -314,6 +326,9 @@ func (c *Client) checkConn() error {
if c.co == nil { if c.co == nil {
return ErrNoActiveConnection return ErrNoActiveConnection
} }
if err := c.sc.Noop(); err != nil {
return ErrNoActiveConnection
}
if err := c.co.SetDeadline(time.Now().Add(c.cto)); err != nil { if err := c.co.SetDeadline(time.Now().Add(c.cto)); err != nil {
return ErrDeadlineExtendFailed return ErrDeadlineExtendFailed
} }

View file

@ -41,6 +41,10 @@ func main() {
os.Exit(1) os.Exit(1)
} }
defer func() { 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 { if err := c.Close(); err != nil {
fmt.Printf("failed to close: %s\n", err) fmt.Printf("failed to close: %s\n", err)
os.Exit(1) os.Exit(1)