fix(mail): do not fail testmail command when the connection could not be closed.
All checks were successful
continuous-integration/drone/push Build is passing

Resolves https://github.com/go-vikunja/vikunja/issues/300
This commit is contained in:
kolaente 2024-08-12 11:05:56 +02:00
parent 4a4ed2cf89
commit 40bb86bee5
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 7 additions and 4 deletions

View File

@ -17,6 +17,8 @@
package cmd
import (
"strings"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/initialize"
"code.vikunja.io/api/pkg/log"
@ -51,10 +53,11 @@ var testmailCmd = &cobra.Command{
opts, err := notifications.RenderMail(message)
if err != nil {
log.Errorf("Error sending test mail: %s", err.Error())
log.Errorf("Error rendering test mail: %s", err.Error())
return
}
if err := mail.SendTestMail(opts); err != nil {
if err := mail.SendTestMail(opts); err != nil &&
strings.HasPrefix(err.Error(), "failed to close connction: not connected to SMTP server") {
log.Errorf("Error sending test mail: %s", err.Error())
return
}

View File

@ -18,6 +18,7 @@ package mail
import (
"embed"
"fmt"
"io"
"code.vikunja.io/api/pkg/config"
@ -60,8 +61,7 @@ type header struct {
// It works without a queue.
func SendTestMail(opts *Opts) error {
if config.MailerHost.GetString() == "" {
log.Warning("Mailer seems to be not configured! Please see the config docs for more details.")
return nil
return fmt.Errorf("mailer is not configured! Please see the config docs for more details")
}
c, err := getClient()