Skip to content

Commit

Permalink
Merge pull request #107 from GSM-MSG/104-email-template
Browse files Browse the repository at this point in the history
🔀 :: 이메일 전송 템플릿 변경
  • Loading branch information
baekteun authored Mar 10, 2023
2 parents 241e65d + 62b66fc commit 2d5a4c0
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EmailController(
@GetMapping("/authentication")
fun emailVerification(@RequestParam email: String, @RequestParam uuid: String): ResponseEntity<String> {
mailVerificationService.execute(email, uuid)
return ResponseEntity.ok("완료되었습니다!<br> 회원가입을 진행해주세요.")
return ResponseEntity.ok("완료되었습니다!<br> 다음 단계를 진행해주세요.")
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import org.springframework.scheduling.annotation.Async
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.thymeleaf.TemplateEngine
import org.thymeleaf.context.Context
import org.thymeleaf.spring5.SpringTemplateEngine
import java.util.*
import javax.mail.Message
import javax.mail.MessagingException

@Service
class MailSendService(
private val mailSender: JavaMailSender,
private val emailAuthRepository: EmailAuthRepository
private val emailAuthRepository: EmailAuthRepository,
private val templateEngine: TemplateEngine
) {

fun execute(emailSendDto: EmailSendDto) {
Expand All @@ -36,19 +40,27 @@ class MailSendService(
)
if(authEntity.authentication)
throw AlreadyAuthenticatedEmailException()
if (authEntity.attemptCount >= 3) throw ManyRequestEmailAuthException()
if (authEntity.attemptCount >= 5) throw ManyRequestEmailAuthException()
val updateEmailAuth = authEntity.resendEmailAuth(value)
emailAuthRepository.save(updateEmailAuth)
try {
val message = mailSender.createMimeMessage()
val msg =
"<a href=\"https://server.gauth.co.kr/email/authentication?email=$email&uuid=$value\" style=\"padding: 10px; border: none; color: white; background-color: skyblue; border-radius: 8px; align-self: center; text-align: center;\">인증하기</a>"
val mailTemplate = createMailTemplate(email, value)
message.addRecipients(Message.RecipientType.TO, emailSendDto.email)
message.subject = "[GAuth] 이메일 인증"
message.setText(msg, "utf-8", "html")
message.setText(mailTemplate, "utf-8", "html")
mailSender.send(message)
} catch (ex: MessagingException) {
throw MessageSendFailException()
}
}

private fun createMailTemplate(email: String, code: String): String {
val context = Context()
context.setVariables(mapOf(
"email" to email,
"code" to code
))
return templateEngine.process("mail", context)
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/msg/gauth/global/mail/MailConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.mail.javamail.JavaMailSender
import org.springframework.mail.javamail.JavaMailSenderImpl
import org.thymeleaf.TemplateEngine
import org.thymeleaf.spring5.SpringTemplateEngine

@Configuration
class MailConfig(
Expand All @@ -27,4 +29,7 @@ class MailConfig(
this.javaMailProperties["mail.smtp.starttls.required"] = true
}

@Bean
fun templateEngine(): TemplateEngine =
SpringTemplateEngine()
}
107 changes: 107 additions & 0 deletions src/main/resources/templates/mail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="style.css" />
</head>
<body style="margin: 0; padding: 0; box-sizing: border-box">
<div
style="
width: 100%;
min-height: 100vh;
background: #ffffff;
padding: 31px 42px;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
"
>
<hr style="width: 100%; height: 5px; background: #5499d9" />
<div
style="
width: 100%;
height: 346px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
"
>
<svg
width="105"
height="38"
viewBox="0 0 105 38"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="88.3984" cy="2" r="2" fill="#5499D9" />
<circle cx="75.3984" cy="2" r="2" fill="#5499D9" />
<path
d="M9.84375 37.3984C8.07292 37.3984 6.51042 37.1445 5.15625 36.6367C3.80208 36.1419 2.72786 35.4193 1.93359 34.4688C1.15234 33.5182 0.703125 32.3854 0.585938 31.0703H4.84375C5.03906 32.0469 5.56641 32.7826 6.42578 33.2773C7.29818 33.7852 8.42448 34.0391 9.80469 34.0391C11.5495 34.0391 12.8971 33.6549 13.8477 32.8867C14.8112 32.1185 15.2995 30.9271 15.3125 29.3125V25.1328H15.0391C14.5052 26.1094 13.7695 26.9492 12.832 27.6523C11.9076 28.3424 10.5859 28.6875 8.86719 28.6875C7.17448 28.6875 5.65755 28.2773 4.31641 27.457C2.97526 26.6367 1.92057 25.4388 1.15234 23.8633C0.384115 22.2747 0 20.3802 0 18.1797C0 15.9792 0.384115 14.0781 1.15234 12.4766C1.92057 10.862 2.97526 9.63151 4.31641 8.78516C5.67057 7.9388 7.20052 7.51562 8.90625 7.51562C10.1172 7.51562 11.1263 7.71745 11.9336 8.12109C12.7539 8.51172 13.3854 8.96745 13.8281 9.48828C14.2708 9.99609 14.6875 10.5755 15.0781 11.2266H15.3516V7.78906H19.4141V29.4688C19.4141 31.2266 19.0039 32.6979 18.1836 33.8828C17.3763 35.0677 16.25 35.9466 14.8047 36.5195C13.3724 37.1055 11.7188 37.3984 9.84375 37.3984ZM4.25781 18.2578C4.24479 20.3932 4.72005 22.0924 5.68359 23.3555C6.64714 24.6055 8.02083 25.237 9.80469 25.25C11.5755 25.237 12.9427 24.6185 13.9062 23.3945C14.8698 22.1706 15.3516 20.4583 15.3516 18.2578C15.3516 16.8125 15.1367 15.5495 14.707 14.4688C14.2773 13.388 13.6458 12.5547 12.8125 11.9688C11.9792 11.3698 10.9766 11.0703 9.80469 11.0703C8.60677 11.0703 7.59115 11.3828 6.75781 12.0078C5.92448 12.6198 5.29297 13.4727 4.86328 14.5664C4.44661 15.6471 4.24479 16.8776 4.25781 18.2578Z"
fill="#1C1C1C"
/>
<path
d="M24.3156 23.0234C24.3026 20.8229 25.0383 19.2539 26.5227 18.3164C28.0201 17.3789 29.9276 16.8255 32.2453 16.6562C35.2531 16.487 37.1086 16.3893 37.8117 16.3633L37.7922 14.6641C37.8052 13.4531 37.4406 12.5221 36.6984 11.8711C35.9693 11.207 34.9016 10.875 33.4953 10.875C32.3104 10.875 31.3404 11.1224 30.5852 11.6172C29.8299 12.099 29.3417 12.75 29.1203 13.5703H24.9797C25.1099 12.3984 25.5461 11.3568 26.2883 10.4453C27.0305 9.52083 28.0331 8.80469 29.2961 8.29688C30.5591 7.77604 32.0109 7.51562 33.6516 7.51562C34.9927 7.51562 36.2818 7.72396 37.5187 8.14062C38.7687 8.54427 39.8234 9.29948 40.6828 10.4062C41.5422 11.5 41.9719 12.9974 41.9719 14.8984V29H37.9094V26.1094H37.7531C37.2714 27.0339 36.5031 27.8281 35.4484 28.4922C34.3937 29.1432 33.0656 29.4688 31.4641 29.4688C30.1099 29.4688 28.8859 29.2148 27.7922 28.707C26.7115 28.1992 25.8586 27.4635 25.2336 26.5C24.6216 25.5234 24.3156 24.3646 24.3156 23.0234ZM28.3781 23.0625C28.3781 24.0521 28.7427 24.8138 29.4719 25.3477C30.2141 25.8685 31.1906 26.1354 32.4016 26.1484C33.4953 26.1484 34.4523 25.9271 35.2727 25.4844C36.093 25.0417 36.7245 24.4557 37.1672 23.7266C37.6099 22.9844 37.8312 22.1901 37.8312 21.3438L37.8117 19.4102L32.8312 19.7422C31.412 19.8464 30.3117 20.1719 29.5305 20.7188C28.7622 21.2656 28.3781 22.0469 28.3781 23.0625Z"
fill="#1C1C1C"
/>
<path
d="M61.2875 7.78906H65.4281V18.3945V29H61.3656V25.3281H61.1312C60.6234 26.513 59.8227 27.4701 58.7289 28.1992C57.6482 28.9154 56.3396 29.2734 54.8031 29.2734C53.4229 29.2734 52.2055 28.9674 51.1508 28.3555C50.0961 27.7435 49.2758 26.8385 48.6898 25.6406C48.1039 24.4297 47.8109 22.9714 47.8109 21.2656V7.78906H51.9906V20.7578C51.9906 21.7083 52.1729 22.5417 52.5375 23.2578C52.9021 23.974 53.4034 24.5273 54.0414 24.918C54.6924 25.2956 55.4411 25.4844 56.2875 25.4844C57.1078 25.4844 57.9021 25.2891 58.6703 24.8984C59.4385 24.4948 60.0635 23.8958 60.5453 23.1016C61.0401 22.2943 61.2875 21.3177 61.2875 20.1719V7.78906Z"
fill="#1C1C1C"
/>
<path
d="M81.2281 11.1094H76.8922V22.75C76.9052 23.8438 77.1331 24.5924 77.5758 24.9961C78.0185 25.3867 78.637 25.5885 79.4313 25.6016C80.0563 25.6016 80.7594 25.5625 81.5406 25.4844V29.1172C80.7854 29.2214 79.913 29.2734 78.9234 29.2734C77.7906 29.2734 76.7555 29.0651 75.818 28.6484C74.8805 28.2318 74.1318 27.6003 73.5719 26.7539C73.012 25.8945 72.7385 24.8464 72.7516 23.6094V11.1094H69.6266V7.78906H72.7516H76.8922H81.2281V11.1094Z"
fill="#1C1C1C"
/>
<path
d="M90.2703 29H86.0906V7.78906H90.1922V11.2656H90.4656C90.9865 10.0677 91.7612 9.14323 92.7898 8.49219C93.8315 7.84115 95.1531 7.51562 96.7547 7.51562C98.226 7.51562 99.5021 7.82161 100.583 8.43359C101.677 9.03255 102.523 9.93099 103.122 11.1289C103.721 12.3268 104.02 13.7917 104.02 15.5234V29H99.8406V16.0312C99.8406 14.4688 99.4435 13.2578 98.6492 12.3984C97.8549 11.5391 96.7547 11.1094 95.3484 11.1094C94.3588 11.1094 93.4799 11.3177 92.7117 11.7344C91.9435 12.151 91.3445 12.763 90.9148 13.5703C90.4852 14.3646 90.2703 15.3151 90.2703 16.4219V29Z"
fill="#1C1C1C"
/>
</svg>
<h1 style="font-size: 24px; font-weight: 700; color: #000000">
<span style="color: #5499d9">메일인증</span> 안내입니다.
</h1>
<hr
style="
width: 100px;
background: #929292;
height: 2px;
border-radius: 50px;
"
/>
<p
style="
font-weight: 600;
font-size: 12px;
color: #929292;
text-align: center;
"
>
GAuth에서 보낸 인증 메일입니다.<br />
이메일 인증을 위해 아래 버튼을 눌러주세요.
</p>
<a
href="https://server.gauth.co.kr/email/authentication?email=${email}&uuid=${code}"
style="
cursor: pointer;
width: 137px;
height: 32px;
background: #5499d9;
border-radius: 10px;
color: #ffffff;
border: none;
display: flex;
justify-content: center;
align-items: center;
"
>
인증 확인
</a>
</div>
<hr style="width: 100%; height: 5px; background: #5499d9" />
</div>
</body>
</html>

0 comments on commit 2d5a4c0

Please sign in to comment.