package auth import ( "fmt" "html" "strings" ) const ( loginEmailFromName = "hello" loginEmailFromEmail = "hello@auth.moteva.local" loginEmailBrandName = "Moteva" ) type EmailTemplateOptions struct { FromName string FromEmail string BrandName string } func buildLoginEmail(toEmail string, code string, opts EmailTemplateOptions) *EmailMessage { toEmail = normalizeEmail(toEmail) code = strings.TrimSpace(code) fromName := fallbackString(opts.FromName, loginEmailFromName) fromEmail := fallbackString(opts.FromEmail, loginEmailFromEmail) brandName := fallbackString(opts.BrandName, loginEmailBrandName) return &EmailMessage{ FromName: fromName, FromEmail: fromEmail, ToEmail: toEmail, Subject: "Welcome to " + brandName + "!", Code: code, Text: fmt.Sprintf( "Hi,\n\nWelcome to us! Enter this code within the next 10 minutes to log in:\n\n%s\n\nPlease ignore this email if this wasn't you trying to create a %s account.\n\nThe %s Team", code, brandName, brandName, ), HTML: loginEmailHTML(code, brandName), } } func loginEmailHTML(code string, brandName string) string { escapedCode := html.EscapeString(code) escapedBrand := html.EscapeString(brandName) return `
M ` + escapedBrand + `

Hi,

Welcome to us! Enter this code within the next 10 minutes to log in:

` + escapedCode + `

Please ignore this email if this wasn't you trying to create a ` + escapedBrand + ` account.

The ` + escapedBrand + ` Team

` } func fallbackString(value string, fallback string) string { value = strings.TrimSpace(value) if value == "" { return fallback } return value }