feat(mail): don't try to authenticate when no username and password was provided

This commit is contained in:
kolaente 2022-08-03 13:41:42 +02:00
parent aed1ad6d96
commit d47edac376
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -48,7 +48,6 @@ func getClient() (*mail.Client, error) {
} }
opts := []mail.Option{ opts := []mail.Option{
mail.WithSMTPAuth(authType),
mail.WithPort(config.MailerPort.GetInt()), mail.WithPort(config.MailerPort.GetInt()),
mail.WithTLSPolicy(tlsPolicy), mail.WithTLSPolicy(tlsPolicy),
//#nosec G402 //#nosec G402
@ -58,6 +57,10 @@ func getClient() (*mail.Client, error) {
}), }),
} }
if config.MailerUsername.GetString() != "" && config.MailerPassword.GetString() != "" {
opts = append(opts, mail.WithSMTPAuth(authType))
}
if config.MailerUsername.GetString() != "" { if config.MailerUsername.GetString() != "" {
opts = append(opts, mail.WithUsername(config.MailerUsername.GetString())) opts = append(opts, mail.WithUsername(config.MailerUsername.GetString()))
} }