diff --git a/services/email.go b/services/email.go index 29ebc77..c36403d 100644 --- a/services/email.go +++ b/services/email.go @@ -3,6 +3,7 @@ package services import ( "fmt" "log" + "time" "github.com/ayush00git/cms-web/helpers" "github.com/wneessen/go-mail" @@ -33,6 +34,92 @@ func SendMail(to, subject, body string) (error) { return c.DialAndSend(m) } +// buildEmailHTML builds the shared HTML email template used across all +// outgoing mails, so every mail shares the same look and feel. +func buildEmailHTML(heading, message, buttonText, buttonURL string) string { + return fmt.Sprintf(` + + +
+ + + + +
+
+
+
|
+
Thanks for signing up! get started with cms.
-- Get Started! -
- - - `, verificationURL) - + mail := buildEmailHTML( + "Verify your account", + "Thanks for signing up! Get started with CMS.", + "Verify Email Address", + verificationURL, + ) + err = SendMail(email, "Verification of your cms account", mail) if err != nil { return err @@ -84,24 +158,12 @@ func SendPasswordResetMail(userID uint, email, role string) error { resetURL := fmt.Sprintf(`%s/account/reset-password?user=%s`, frontendURL, token) // send the email - mail := fmt.Sprintf(` - - - - - - - -- Reset! -
- - - `, resetURL) + mail := buildEmailHTML( + "Reset your password", + "We received a request to reset your password.", + "Reset Password", + resetURL, + ) err = SendMail(email, "Reset your cms account password", mail) if err != nil { @@ -112,25 +174,14 @@ func SendPasswordResetMail(userID uint, email, role string) error { } func SendPostMailToAdmins(email, postURL string) error { - mail := fmt.Sprintf(` - - - - - - - -- View Updates -
- - - `, postURL) -// sends the email + mail := buildEmailHTML( + "cms: updates on a recent complaint", + "There has been an update on a complaint.", + "View Updates", + postURL, + ) + + // sends the email err := SendMail(email, "New complaint recieved", mail) if err != nil { return err @@ -142,24 +193,12 @@ func SendPostMailToAdmins(email, postURL string) error { // Send email to peoples in the conversation thread expect the ignoreEmail // one, to prevent sending the mail to user itself for its events func SendMailToPeopleInThread(emails []string, ignoreEmail string, postURL string) error { - mail := fmt.Sprintf(` - - - - - - - -- View Updates -
- - - `, postURL) + mail := buildEmailHTML( + "cms: updates on a recent complaint", + "There has been an update on a complaint where you were mentioned.", + "View Updates", + postURL, + ) for _, email := range emails { if email == ignoreEmail {