Fix panic on invalid smtp config

This commit is contained in:
kolaente 2021-08-02 00:05:13 +02:00
parent 4c5f457313
commit f237afd2ac
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -67,21 +67,24 @@ func StartMailDaemon() {
if !open { if !open {
if s, err = d.Dial(); err != nil { if s, err = d.Dial(); err != nil {
log.Error("Error during connect to smtp server: %s", err) log.Error("Error during connect to smtp server: %s", err)
break
} }
open = true open = true
} }
if err := gomail.Send(s, m); err != nil { if err := gomail.Send(s, m); err != nil {
log.Error("Error when sending mail: %s", err) log.Error("Error when sending mail: %s", err)
break
} }
// Close the connection to the SMTP server if no email was sent in // Close the connection to the SMTP server if no email was sent in
// the last 30 seconds. // the last 30 seconds.
case <-time.After(config.MailerQueueTimeout.GetDuration() * time.Second): case <-time.After(config.MailerQueueTimeout.GetDuration() * time.Second):
if open { if open {
open = false
if err := s.Close(); err != nil { if err := s.Close(); err != nil {
log.Error("Error closing the mail server connection: %s\n", err) log.Error("Error closing the mail server connection: %s\n", err)
break
} }
log.Infof("Closed connection to mailserver") log.Infof("Closed connection to mailserver")
open = false
} }
} }
} }