Skip to content

Commit

Permalink
Add email content type specification (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 authored Dec 29, 2023
1 parent aef82e3 commit 044fbb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 044fbb3

Please sign in to comment.