feat: allow empty user and password in SMTP configuration

This commit is contained in:
Elias Schneider
2024-11-28 12:14:03 +01:00
parent f9fa2c6706
commit a9f4dada32
2 changed files with 15 additions and 10 deletions

View File

@@ -118,14 +118,19 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
return fmt.Errorf("failed to connect to SMTP server: %w", err)
}
// Set up the authentication
auth := smtp.PlainAuth("",
srv.appConfigService.DbConfig.SmtpUser.Value,
srv.appConfigService.DbConfig.SmtpPassword.Value,
srv.appConfigService.DbConfig.SmtpHost.Value,
)
if err := client.Auth(auth); err != nil {
return fmt.Errorf("failed to authenticate SMTP client: %w", err)
smtpUser := srv.appConfigService.DbConfig.SmtpUser.Value
smtpPassword := srv.appConfigService.DbConfig.SmtpPassword.Value
// Set up the authentication if user or password are set
if smtpUser != "" || smtpPassword != "" {
auth := smtp.PlainAuth("",
srv.appConfigService.DbConfig.SmtpUser.Value,
srv.appConfigService.DbConfig.SmtpPassword.Value,
srv.appConfigService.DbConfig.SmtpHost.Value,
)
if err := client.Auth(auth); err != nil {
return fmt.Errorf("failed to authenticate SMTP client: %w", err)
}
}
// Send the email

View File

@@ -35,8 +35,8 @@
const formSchema = z.object({
smtpHost: z.string().min(1),
smtpPort: z.number().min(1),
smtpUser: z.string().min(1),
smtpPassword: z.string().min(1),
smtpUser: z.string(),
smtpPassword: z.string(),
smtpFrom: z.string().email(),
smtpTls: z.boolean(),
smtpSkipCertVerify: z.boolean()