From 044fbb3da528b570250f940a413b2cea3f1de0f1 Mon Sep 17 00:00:00 2001 From: Sheikah45 <66929319+Sheikah45@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:31:33 -0500 Subject: [PATCH] Add email content type specification (#214) --- .../userservice/backend/email/EmailService.kt | 6 +++--- .../faforever/userservice/backend/email/MailSender.kt | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt b/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt index 6f1f598a..6697ac25 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt @@ -54,16 +54,16 @@ class EmailService( fun sendActivationMail(username: String, email: String, activationUrl: String) { val mailBody = mailBodyBuilder.buildAccountActivationBody(username, activationUrl) - mailSender.sendMail(email, properties.account().registration().subject(), mailBody) + mailSender.sendMail(email, properties.account().registration().subject(), mailBody, ContentType.HTML) } fun sendWelcomeToFafMail(username: String, email: String) { val mailBody = mailBodyBuilder.buildWelcomeToFafBody(username) - mailSender.sendMail(email, properties.account().registration().welcomeSubject(), mailBody) + mailSender.sendMail(email, properties.account().registration().welcomeSubject(), mailBody, ContentType.HTML) } fun sendPasswordResetMail(username: String, email: String, passwordResetUrl: String) { val mailBody = mailBodyBuilder.buildPasswordResetBody(username, passwordResetUrl) - mailSender.sendMail(email, properties.account().passwordReset().subject(), mailBody) + mailSender.sendMail(email, properties.account().passwordReset().subject(), mailBody, ContentType.HTML) } } diff --git a/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt b/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt index b344ca72..e183b066 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt @@ -8,9 +8,16 @@ import jakarta.enterprise.context.ApplicationScoped class MailSender( private val mailer: Mailer, ) { - fun sendMail(toEmail: String, subject: String, content: String) { + fun sendMail(toEmail: String, subject: String, content: String, contentType: ContentType) { mailer.send( - Mail.withHtml(toEmail, subject, content), + when (contentType) { + ContentType.TEXT -> Mail.withText(toEmail, subject, content) + ContentType.HTML -> Mail.withHtml(toEmail, subject, content) + }, ) } } + +enum class ContentType { + TEXT, HTML +}