"Improve error checking in SMTP client creation"

A change was made in the SMTP client creation process to add more robust error handling. The new logic checks if the client is null after being created and, if true, returns an error. This update can help prevent potential null pointer exceptions in runtime, ultimately leading to more stable application.
This commit is contained in:
Winni Neessen 2023-11-29 16:25:35 +01:00
parent cf678be9dd
commit bb18ef9e93
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -511,10 +511,15 @@ func (c *Client) DialWithContext(pc context.Context) error {
return err return err
} }
c.sc, err = smtp.NewClient(c.co, c.host) sc, err := smtp.NewClient(c.co, c.host)
if err != nil { if err != nil {
return err return err
} }
if sc == nil {
return fmt.Errorf("SMTP client is nil")
}
c.sc = sc
if c.l != nil { if c.l != nil {
c.sc.SetLogger(c.l) c.sc.SetLogger(c.l)
} }