-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fd1eeb
commit f5a46a2
Showing
9 changed files
with
109 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/healthiee/rest/lib/mail/model/MailBuilderParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package healthiee.rest.lib.mail.model | ||
|
||
import java.util.* | ||
|
||
data class MailBuilderParams( | ||
val registered: Boolean, | ||
val code: UUID, | ||
) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/healthiee/rest/lib/mail/model/MailSenderParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package healthiee.rest.lib.mail.model | ||
|
||
data class MailSenderParams( | ||
val targetEmail: String, | ||
val subject: String, | ||
val body: String, | ||
) |
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/healthiee/rest/lib/mail/sender/AmazonSESMailSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package healthiee.rest.lib.mail.sender | ||
|
||
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService | ||
import com.amazonaws.services.simpleemail.model.Body | ||
import com.amazonaws.services.simpleemail.model.Content | ||
import com.amazonaws.services.simpleemail.model.Destination | ||
import com.amazonaws.services.simpleemail.model.Message | ||
import com.amazonaws.services.simpleemail.model.SendEmailRequest | ||
import healthiee.rest.lib.mail.model.MailSenderParams | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class AmazonSESMailSender( | ||
private val ses: AmazonSimpleEmailService, | ||
) : MailSender { | ||
|
||
override fun send(params: MailSenderParams) { | ||
val mailRequest = SendEmailRequest() | ||
.withSource("[email protected]") | ||
.withDestination(Destination().withToAddresses(params.targetEmail)) | ||
.withMessage( | ||
Message() | ||
.withSubject(Content(params.subject).withCharset(Charsets.UTF_8.name())) | ||
.withBody(Body().withHtml(Content(params.body))) | ||
) | ||
|
||
ses.sendEmail(mailRequest) | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/healthiee/rest/lib/mail/sender/MailSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package healthiee.rest.lib.mail.sender | ||
|
||
import healthiee.rest.lib.mail.model.MailSenderParams | ||
|
||
|
||
interface MailSender { | ||
|
||
fun send(params: MailSenderParams) | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/healthiee/rest/lib/mail/template/AuthMailBodyBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package healthiee.rest.lib.mail.template | ||
|
||
import healthiee.rest.lib.mail.model.MailBuilderParams | ||
import org.springframework.stereotype.Component | ||
import org.thymeleaf.context.Context | ||
import org.thymeleaf.spring6.SpringTemplateEngine | ||
|
||
@Component | ||
class AuthMailBodyBuilder( | ||
private val templateEngine: SpringTemplateEngine, | ||
) : MailBuilder { | ||
|
||
override fun makeSubject(params: MailBuilderParams): String { | ||
return "[Healthiee] ${if (params.registered) "로그인" else "회원가입"}" | ||
} | ||
|
||
override fun makeBody(params: MailBuilderParams): String { | ||
val endpoint = | ||
if (params.registered) "email-login" | ||
else "authcompleted" | ||
val context = Context().apply { | ||
setVariable("url", "http://localhost:3000/${endpoint}?code=${params.code}") | ||
setVariable("text", if (params.registered) "로그인" else "회원가입") | ||
} | ||
return templateEngine.process("code", context) | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/healthiee/rest/lib/mail/template/MailBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package healthiee.rest.lib.mail.template | ||
|
||
import healthiee.rest.lib.mail.model.MailBuilderParams | ||
|
||
interface MailBuilder { | ||
|
||
fun makeSubject(params: MailBuilderParams): String | ||
fun makeBody(params: MailBuilderParams): String | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters