send welcome email
This commit is contained in:
parent
219d254b96
commit
d2560630f4
2 changed files with 48 additions and 1 deletions
|
|
@ -327,7 +327,10 @@ func (s *AuthService) CompleteOnboarding(userID, name string) error {
|
||||||
|
|
||||||
user, err := s.userRepository.ByID(userID)
|
user, err := s.userRepository.ByID(userID)
|
||||||
if err == nil {
|
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)
|
slog.Info("onboarding completed", "user_id", user.ID, "name", name)
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,34 @@ func (s *EmailService) SendMagicLinkEmail(email, token, name string) error {
|
||||||
return err
|
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) {
|
func magicLinkEmailTemplate(magicURL, appName string) (string, string) {
|
||||||
subject := fmt.Sprintf("Sign in to %s", appName)
|
subject := fmt.Sprintf("Sign in to %s", appName)
|
||||||
body := fmt.Sprintf(`Click this link to sign in to your account:
|
body := fmt.Sprintf(`Click this link to sign in to your account:
|
||||||
|
|
@ -187,3 +215,19 @@ The %s Team`, magicURL, appName)
|
||||||
|
|
||||||
return subject, body
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue