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
This commit is contained in:
kolaente 2022-07-12 15:46:21 +02:00
parent 4bb77b5539
commit c906fc2b07
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -47,17 +47,27 @@ func getClient() (*mail.Client, error) {
tlsPolicy = mail.TLSMandatory tlsPolicy = mail.TLSMandatory
} }
return mail.NewClient( opts := []mail.Option{
config.MailerHost.GetString(),
mail.WithSMTPAuth(authType), mail.WithSMTPAuth(authType),
mail.WithUsername(config.MailerUsername.GetString()),
mail.WithPassword(config.MailerPassword.GetString()),
mail.WithPort(config.MailerPort.GetInt()), mail.WithPort(config.MailerPort.GetInt()),
mail.WithTLSPolicy(tlsPolicy), mail.WithTLSPolicy(tlsPolicy),
//#nosec G402 //#nosec G402
mail.WithTLSConfig(&tls.Config{ mail.WithTLSConfig(&tls.Config{
InsecureSkipVerify: config.MailerSkipTLSVerify.GetBool(), 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...,
) )
} }