Fix email config not reading from env vars

Viper requires SetDefault to be called for env vars to be
automatically bound. Added defaults for EMAIL_HOST_USER and
EMAIL_HOST_PASSWORD.

Also added info logging to show email config on startup for debugging.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-26 23:23:26 -06:00
parent 9ec1bddd99
commit 2b03f03604
2 changed files with 12 additions and 1 deletions

View File

@@ -75,13 +75,22 @@ func main() {
// Initialize email service
var emailService *services.EmailService
log.Info().
Str("email_host", cfg.Email.Host).
Str("email_user", cfg.Email.User).
Str("email_from", cfg.Email.From).
Int("email_port", cfg.Email.Port).
Msg("Email config loaded")
if cfg.Email.Host != "" && cfg.Email.User != "" {
emailService = services.NewEmailService(&cfg.Email)
log.Info().
Str("host", cfg.Email.Host).
Msg("Email service initialized")
} else {
log.Warn().Msg("Email service not configured - emails will not be sent")
log.Warn().
Str("host", cfg.Email.Host).
Str("user", cfg.Email.User).
Msg("Email service not configured - emails will not be sent")
}
// Setup router with dependencies

View File

@@ -209,6 +209,8 @@ func setDefaults() {
viper.SetDefault("EMAIL_HOST", "smtp.gmail.com")
viper.SetDefault("EMAIL_PORT", 587)
viper.SetDefault("EMAIL_USE_TLS", true)
viper.SetDefault("EMAIL_HOST_USER", "")
viper.SetDefault("EMAIL_HOST_PASSWORD", "")
viper.SetDefault("DEFAULT_FROM_EMAIL", "MyCrib <noreply@mycrib.com>")
// Push notification defaults