Hi %s,
We received a request to reset your password. Click the button below to create a new password:
Note: This link will expire in 1 hour.
If you didn't request this, you can safely ignore this email.
package email import ( "fmt" "log" "net/smtp" "os" "strconv" ) type Service struct { smtpServer string smtpPort int smtpUser string smtpPassword string from string } func NewService() *Service { smtpServer := os.Getenv("SMTP_SERVER") if smtpServer == "" { smtpServer = "localhost" } smtpPort := os.Getenv("SMTP_PORT") if smtpPort == "" { smtpPort = "587" } port, err := strconv.Atoi(smtpPort) if err != nil { port = 587 } smtpUser := os.Getenv("SMTP_USER") if smtpUser == "" { smtpUser = "noreply@rideaware.app" } smtpPassword := os.Getenv("SMTP_PASSWORD") from := os.Getenv("SENDER_EMAIL") if from == "" { from = "noreply@rideaware.app" } log.Printf("📧 Email service initialized: %s@%s:%d", smtpUser, smtpServer, port) return &Service{ smtpServer: smtpServer, smtpPort: port, smtpUser: smtpUser, smtpPassword: smtpPassword, from: from, } } func (s *Service) sendEmail(to []string, subject, htmlBody string) error { log.Printf("📧 Preparing to send email to: %s (Subject: %s)", to[0], subject) // Create message headers := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: %s\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=\"UTF-8\"\r\n\r\n", s.from, to[0], subject, ) message := headers + htmlBody // SMTP server address addr := fmt.Sprintf("%s:%d", s.smtpServer, s.smtpPort) log.Printf("📧 Connecting to SMTP: %s", addr) // Create SMTP authentication auth := smtp.PlainAuth("", s.smtpUser, s.smtpPassword, s.smtpServer) // Send email log.Printf("📧 Sending email via SMTP...") err := smtp.SendMail(addr, auth, s.from, to, []byte(message)) if err != nil { log.Printf("❌ Email send failed: %v", err) return fmt.Errorf("failed to send email: %w", err) } log.Printf("✅ Email sent successfully to: %s", to[0]) return nil } func (s *Service) SendPasswordResetEmail(email, username, resetLink string) error { log.Printf("🔑 Sending password reset email to: %s", email) subject := "Reset Your RideAware Password" htmlBody := fmt.Sprintf(`
Hi %s,
We received a request to reset your password. Click the button below to create a new password:
Note: This link will expire in 1 hour.
If you didn't request this, you can safely ignore this email.
Hi %s,
Your account has been created successfully! 🚀
You're now ready to:
Get started by logging in to your account and setting up your profile.