Skip to content

Commit

Permalink
Merge pull request #129 from TeamMiso/develop
Browse files Browse the repository at this point in the history
๐Ÿ”€ :: master ๋ธŒ๋žœ์น˜๋กœ ๋จธ์ง€
  • Loading branch information
uuuuuuuk authored Apr 29, 2024
2 parents 0d2ce16 + af8cfd8 commit bd75624
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 23 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ dependencies {

// web_flux
implementation(Dependencies.WEB_FLUX)

// thymeleaf
implementation(Dependencies.THYMELEAF)
}

tasks.withType<KotlinCompile> {
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ object Dependencies {

// web_flux
const val WEB_FLUX = "org.springframework.boot:spring-boot-starter-webflux"

// thymeleaf
const val THYMELEAF = "org.springframework.boot:spring-boot-starter-thymeleaf"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,31 @@ import andreas311.miso.domain.email.domain.Email
import org.springframework.mail.javamail.JavaMailSender
import org.springframework.mail.javamail.MimeMessageHelper
import org.springframework.stereotype.Component
import org.thymeleaf.context.Context
import org.thymeleaf.spring5.SpringTemplateEngine
import java.util.*
import javax.mail.MessagingException

@Component
class EmailSendAdapter(
private val javaMailSender: JavaMailSender,
private val commandEmailPort: CommandEmailPort
private val commandEmailPort: CommandEmailPort,
private val springTemplateEngine: SpringTemplateEngine
) : EmailSendPort {
override fun sendEmailAuthKey(email: String) {
val randomKey = createRandomKey()
sendAuthEmail(email, randomKey)
}

private fun sendAuthEmail(email: String, randomKey: String) {
val subject = "MISO ์ธ์ฆ๋ฒˆํ˜ธ๊ฐ€ ๋„์ฐฉํ–ˆ์Šต๋‹ˆ๋‹ค!"
val content = buildEmailContent(randomKey)

try {
sendEmail(email, subject, content)
sendEmail(email, randomKey)
} catch (e: MessagingException) {
throw EmailSendFailedException()
}
saveEmailToRepository(email, randomKey)
}

private fun buildEmailContent(randomKey: String): String {
return """
<div style='margin:100px;'>
<h1> ์•ˆ๋…•ํ•˜์„ธ์š” MISO ์ž…๋‹ˆ๋‹ค! </h1>
<br>
<h2><p>์•„๋ž˜ ์ธ์ฆ๋ฒˆํ˜ธ๋ฅผ ์ธ์ฆ ํŽ˜์ด์ง€๋กœ ๋Œ์•„๊ฐ€ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. ์ด์šฉํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!<p></h2>
<br>
<div align='center' style='border:1px solid black; font-family:verdana';>
<h3 style='color:blue;'>์ธ์ฆ๋ฒˆํ˜ธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค!</h3>
<div style='font-size:130%'>
์ธ์ฆ๋ฒˆํ˜ธ : <strong>$randomKey</strong><div><br/>
</div>
""".trimIndent()
}

private fun saveEmailToRepository(email: String, randomKey: String) {
commandEmailPort.saveEmail(
Email(
Expand All @@ -58,12 +43,13 @@ class EmailSendAdapter(
)
}

private fun sendEmail(email: String, subject: String, content: String) {
private fun sendEmail(email: String, randomKey: String) {
val mimeMessage = javaMailSender.createMimeMessage()
val helper = MimeMessageHelper(mimeMessage, true, "utf-8")
val mailTemplate = createMailTemplate(randomKey)
helper.setTo(email)
helper.setSubject(subject)
helper.setText(content, true)
helper.setSubject("MISO ์ธ์ฆ๋ฒˆํ˜ธ๊ฐ€ ๋„์ฐฉํ–ˆ์Šต๋‹ˆ๋‹ค!")
helper.setText(mailTemplate, true)
javaMailSender.send(mimeMessage)
}

Expand All @@ -74,4 +60,15 @@ class EmailSendAdapter(

return randomKey.toString()
}

private fun createMailTemplate(randomKey: String): String {
val content = Context()
val randomKey = randomKey
content.setVariables(
mapOf(
"randomKey" to randomKey
)
)
return springTemplateEngine.process("mailTemplate", content)
}
}
68 changes: 68 additions & 0 deletions src/main/resources/templates/mailTemplate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="ko" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body style="margin: 0; padding: 0">
<div
style="
background-color: #25d07d;
width: 100%;
height: 1rem;
position: absolute;
"
/>
<div style="margin: 0 1.5rem">
<div style="margin-top: 2.5rem">
<img
src="https://project-miso.s3.ap-northeast-2.amazonaws.com/fcm/%EB%AF%B8%EC%86%8C+%EC%95%84%EC%9D%B4%EC%BD%98.png"
alt="miso_icon"
style="width: 2.5rem"
/>
<h1 style="font-size: 1.5625rem; line-height: 160%; margin: 0">
๋ฏธ์†Œ ์ด๋ฉ”์ผ ์ธ์ฆ ๋ฒˆํ˜ธ
</h1>
</div>
<div
style="
margin-top: 1.5rem;
color: #595959;
font-size: 1.25rem;
font-weight: 400;
"
>
์•ˆ๋…•ํ•˜์„ธ์š” MISO์—์š”! <br />
๋ฏธ์†Œ๋ฅผ ์ด์šฉํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ด์š” :) <br />
์œ„ 4์ž๋ฆฌ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์‹œ๋ฉด ํšŒ์›๊ฐ€์ž… ์ ˆ์ฐจ๊ฐ€ ์™„๋ฃŒ๋ผ์š”!
</div>
<div
style="
width: 100%;
border-radius: 0.5rem;
padding: 1rem;
box-sizing: border-box;
background-color: #f2f2f2;
margin-top: 1.5rem;
text-align: center;
"
>
<div style="
margin: 0;
color: #25d07d;
line-height: 140%;
font-size: 2.875rem;
font-weight: 600;
"
th:text="${randomKey}"
>
</div>
<div style="font-size: 1rem; color: #bfbfbf; line-height: 160%"
>ํ™˜๊ฒฝ์„ ์›ƒ์Œ์œผ๋กœ ๋ฐ”๊พธ๋‹ค, MISO</div
>

</div>
</div>
</body>
</html>

0 comments on commit bd75624

Please sign in to comment.