From d2560630f4005a026400826162e5ed4a92de7d50 Mon Sep 17 00:00:00 2001 From: juancwu Date: Wed, 14 Jan 2026 15:25:19 +0000 Subject: [PATCH] send welcome email --- internal/service/auth.go | 5 ++++- internal/service/email.go | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/internal/service/auth.go b/internal/service/auth.go index 2d21190..8274e32 100644 --- a/internal/service/auth.go +++ b/internal/service/auth.go @@ -327,7 +327,10 @@ func (s *AuthService) CompleteOnboarding(userID, name string) error { user, err := s.userRepository.ByID(userID) if err == nil { - // TODO: send welcome email + err = s.emailService.SendWelcomeEmail(user.Email, name) + if err != nil { + slog.Warn("failed to send welcome email", "error", err, "email", user.Email) + } } slog.Info("onboarding completed", "user_id", user.ID, "name", name) diff --git a/internal/service/email.go b/internal/service/email.go index e479723..cf3438c 100644 --- a/internal/service/email.go +++ b/internal/service/email.go @@ -173,6 +173,34 @@ func (s *EmailService) SendMagicLinkEmail(email, token, name string) error { return err } +func (s *EmailService) SendWelcomeEmail(email, name string) error { + dashboardURL := fmt.Sprintf("%s/app/dashboard", s.appURL) + subject, body := welcomeEmailTemplate(name, dashboardURL, s.appName) + + if !s.isProd { + slog.Info("email sent (dev mode)", "type", "welcome", "to", email, "subject", subject, "url", dashboardURL) + return nil + } + + if s.client == nil { + return fmt.Errorf("email service not configured") + } + + params := &EmailParams{ + From: s.fromEmail, + To: []string{email}, + Subject: subject, + Text: body, + } + + _, err := s.client.SendWithContext(context.Background(), params) + if err == nil { + slog.Info("email sent", "type", "welcome", "to", email) + } + + return err +} + func magicLinkEmailTemplate(magicURL, appName string) (string, string) { subject := fmt.Sprintf("Sign in to %s", appName) body := fmt.Sprintf(`Click this link to sign in to your account: @@ -187,3 +215,19 @@ The %s Team`, magicURL, appName) return subject, body } + +func welcomeEmailTemplate(name, dashboardURL, appName string) (string, string) { + subject := fmt.Sprintf("Welcome to %s!", appName) + body := fmt.Sprintf(`Hi %s, + +Your email is verified and your account is active! + +Get started: %s + +If you have questions, reach out to our support team. + +Best, +The %s Team`, name, dashboardURL, appName) + + return subject, body +}