From c906fc2b07624747af1d7819e0fc270fc7b4c070 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 12 Jul 2022 15:46:21 +0200 Subject: [PATCH] fix(mail): don't try to authenticate against the mail server when no credentials are provided Related to https://github.com/go-vikunja/api/issues/34 --- pkg/mail/mail.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/mail/mail.go b/pkg/mail/mail.go index 2583efd4b..0cebb69af 100644 --- a/pkg/mail/mail.go +++ b/pkg/mail/mail.go @@ -47,17 +47,27 @@ func getClient() (*mail.Client, error) { tlsPolicy = mail.TLSMandatory } - return mail.NewClient( - config.MailerHost.GetString(), + opts := []mail.Option{ mail.WithSMTPAuth(authType), - mail.WithUsername(config.MailerUsername.GetString()), - mail.WithPassword(config.MailerPassword.GetString()), mail.WithPort(config.MailerPort.GetInt()), mail.WithTLSPolicy(tlsPolicy), //#nosec G402 mail.WithTLSConfig(&tls.Config{ InsecureSkipVerify: config.MailerSkipTLSVerify.GetBool(), }), + } + + if config.MailerUsername.GetString() != "" { + opts = append(opts, mail.WithUsername(config.MailerUsername.GetString())) + } + + if config.MailerPassword.GetString() != "" { + opts = append(opts, mail.WithPassword(config.MailerPassword.GetString())) + } + + return mail.NewClient( + config.MailerHost.GetString(), + opts..., ) }