Skip to content

Commit

Permalink
feat: allow empty user and password in SMTP configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Nov 28, 2024
1 parent f9fa2c6 commit a9f4dad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions backend/internal/service/email_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a9f4dad

Please sign in to comment.