forgejo-tickets/internal/email/templates.go

91 lines
4.3 KiB
Go

package email
import (
"fmt"
"html"
)
func emailWrapper(content string) string {
return fmt.Sprintf(`<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; color: #1a1a1a;">
%s
<hr style="border: none; border-top: 1px solid #e5e5e5; margin: 30px 0;">
<p style="color: #666; font-size: 13px;">This is an automated message. Please do not reply directly to this email.</p>
</body>
</html>`, content)
}
func renderVerificationEmail(name, verifyURL string) string {
return emailWrapper(fmt.Sprintf(`
<h2 style="color: #111;">Verify your email address</h2>
<p>Hi %s,</p>
<p>Please verify your email address by clicking the button below:</p>
<p style="margin: 30px 0;">
<a href="%s" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: 500;">Verify Email</a>
</p>
<p>Or copy and paste this link into your browser:</p>
<p style="word-break: break-all; color: #2563eb;">%s</p>
<p>This link expires in 24 hours.</p>`, html.EscapeString(name), verifyURL, verifyURL))
}
func renderPasswordResetEmail(name, resetURL string) string {
return emailWrapper(fmt.Sprintf(`
<h2 style="color: #111;">Reset your password</h2>
<p>Hi %s,</p>
<p>We received a request to reset your password. Click the button below to set a new one:</p>
<p style="margin: 30px 0;">
<a href="%s" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: 500;">Reset Password</a>
</p>
<p>Or copy and paste this link into your browser:</p>
<p style="word-break: break-all; color: #2563eb;">%s</p>
<p>This link expires in 1 hour. If you didn't request this, please ignore this email.</p>`, html.EscapeString(name), resetURL, resetURL))
}
func renderTicketClosedEmail(name, ticketTitle, ticketURL string) string {
return emailWrapper(fmt.Sprintf(`
<h2 style="color: #111;">Your ticket has been resolved</h2>
<p>Hi %s,</p>
<p>Your ticket <strong>"%s"</strong> has been resolved by our team.</p>
<p style="margin: 30px 0;">
<a href="%s" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: 500;">View Ticket</a>
</p>
<p>If you believe the issue is not fully resolved, you can add a comment on the ticket page.</p>`, html.EscapeString(name), html.EscapeString(ticketTitle), ticketURL))
}
func renderTicketReplyEmail(name, ticketTitle, ticketURL string) string {
return emailWrapper(fmt.Sprintf(`
<h2 style="color: #111;">New reply on your ticket</h2>
<p>Hi %s,</p>
<p>There is a new reply on your ticket <strong>"%s"</strong>.</p>
<p style="margin: 30px 0;">
<a href="%s" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: 500;">View Ticket</a>
</p>`, html.EscapeString(name), html.EscapeString(ticketTitle), ticketURL))
}
func renderAccountApprovedEmail(name, loginURL string) string {
return emailWrapper(fmt.Sprintf(`
<h2 style="color: #111;">Your account has been approved</h2>
<p>Hi %s,</p>
<p>Your account request has been approved. You can now log in and start creating tickets.</p>
<p style="margin: 30px 0;">
<a href="%s" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: 500;">Log In</a>
</p>`, html.EscapeString(name), loginURL))
}
func renderWelcomeEmail(name, email, tempPassword, loginURL string) string {
return emailWrapper(fmt.Sprintf(`
<h2 style="color: #111;">Welcome!</h2>
<p>Hi %s,</p>
<p>An account has been created for you. Here are your login details:</p>
<table style="margin: 20px 0; border-collapse: collapse;">
<tr><td style="padding: 8px 16px 8px 0; font-weight: 600;">Email:</td><td style="padding: 8px 0;">%s</td></tr>
<tr><td style="padding: 8px 16px 8px 0; font-weight: 600;">Temporary Password:</td><td style="padding: 8px 0; font-family: monospace; background: #f5f5f5; padding: 4px 8px; border-radius: 4px;">%s</td></tr>
</table>
<p style="margin: 30px 0;">
<a href="%s" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: 500;">Log In</a>
</p>
<p>Please change your password after logging in.</p>`, html.EscapeString(name), html.EscapeString(email), html.EscapeString(tempPassword), loginURL))
}