-
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.
Merge pull request #99 from soma-baekgu/feature/BG-380-email-ses
[BG-380]: 이메일 전송 클라이언트 SES로 교체 (2h / 2h)
- Loading branch information
Showing
20 changed files
with
139 additions
and
65 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
api/src/test/kotlin/com/backgu/amaker/api/mail/infra/FakeEmailSender.kt
This file was deleted.
Oops, something went wrong.
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
12 changes: 0 additions & 12 deletions
12
infra/src/main/kotlin/com/backgu/amaker/infra/mail/constants/EmailConstants.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
infra/src/main/kotlin/com/backgu/amaker/infra/mail/service/EmailEventService.kt
This file was deleted.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
...fication/src/main/kotlin/com/backgu/amaker/notification/email/config/EMailSenderConfig.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,17 @@ | ||
package com.backgu.amaker.notification.email.config | ||
|
||
import com.backgu.amaker.notification.email.service.EmailSender | ||
import com.backgu.amaker.notification.email.ses.config.AWSSESConfig | ||
import com.backgu.amaker.notification.email.ses.service.SESEmailService | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import software.amazon.awssdk.services.ses.SesClient | ||
|
||
@Configuration | ||
class EMailSenderConfig { | ||
@Bean | ||
fun mailSender( | ||
sesClient: SesClient, | ||
sesConfig: AWSSESConfig, | ||
): EmailSender = SESEmailService(sesClient, sesConfig) | ||
} |
2 changes: 1 addition & 1 deletion
2
...ker/infra/mail/config/MailClientConfig.kt → ...on/email/gmail/config/MailClientConfig.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
2 changes: 1 addition & 1 deletion
2
.../infra/mail/config/MailConstantsConfig.kt → ...email/gmail/config/MailConstantsConfig.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
6 changes: 2 additions & 4 deletions
6
...maker/infra/mail/infra/HtmlEmailSender.kt → ...tion/email/gmail/infra/HtmlEmailSender.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
4 changes: 2 additions & 2 deletions
4
...il/infra/ThymeleafEmailTemplateBuilder.kt → ...il/infra/ThymeleafEmailTemplateBuilder.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
2 changes: 1 addition & 1 deletion
2
.../notification/mail/service/EmailSender.kt → ...notification/email/service/EmailSender.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
2 changes: 1 addition & 1 deletion
2
...tion/mail/service/EmailTemplateBuilder.kt → ...ion/email/service/EmailTemplateBuilder.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
4 changes: 1 addition & 3 deletions
4
...n/email/templated/TemplateEmailHandler.kt → ...ion/email/service/TemplateEmailHandler.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
26 changes: 26 additions & 0 deletions
26
notification/src/main/kotlin/com/backgu/amaker/notification/email/ses/config/AWSSESConfig.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,26 @@ | ||
package com.backgu.amaker.notification.email.ses.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider | ||
import software.amazon.awssdk.regions.Region | ||
import software.amazon.awssdk.services.ses.SesClient | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "amazon.ses") | ||
class AWSSESConfig { | ||
lateinit var accessKey: String | ||
lateinit var secretKey: String | ||
lateinit var region: String | ||
lateinit var sender: String | ||
|
||
@Bean | ||
fun sesClient(): SesClient = | ||
SesClient | ||
.builder() | ||
.region(Region.of(region)) | ||
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey))) | ||
.build() | ||
} |
73 changes: 73 additions & 0 deletions
73
...ation/src/main/kotlin/com/backgu/amaker/notification/email/ses/service/SESEmailService.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,73 @@ | ||
package com.backgu.amaker.notification.email.ses.service | ||
|
||
import com.backgu.amaker.notification.email.service.EmailSender | ||
import com.backgu.amaker.notification.email.ses.config.AWSSESConfig | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import software.amazon.awssdk.services.ses.SesClient | ||
import software.amazon.awssdk.services.ses.model.Body | ||
import software.amazon.awssdk.services.ses.model.Content | ||
import software.amazon.awssdk.services.ses.model.Destination | ||
import software.amazon.awssdk.services.ses.model.Message | ||
import software.amazon.awssdk.services.ses.model.SendEmailRequest | ||
import software.amazon.awssdk.services.ses.model.SesException | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
class SESEmailService( | ||
private val sesClient: SesClient, | ||
private val sesConfig: AWSSESConfig, | ||
) : EmailSender { | ||
override fun sendEmail( | ||
emailAddress: String, | ||
title: String, | ||
body: String, | ||
) { | ||
val destination: Destination = | ||
Destination | ||
.builder() | ||
.toAddresses(emailAddress) | ||
.build() | ||
|
||
val subjectContent: Content = | ||
Content | ||
.builder() | ||
.data(title) | ||
.charset("UTF-8") | ||
.build() | ||
|
||
val bodyContent: Content = | ||
Content | ||
.builder() | ||
.data(body) | ||
.charset("UTF-8") | ||
.build() | ||
|
||
val body: Body = | ||
Body | ||
.builder() | ||
.html(bodyContent) | ||
.build() | ||
|
||
val message: Message = | ||
Message | ||
.builder() | ||
.subject(subjectContent) | ||
.body(body) | ||
.build() | ||
|
||
val request: SendEmailRequest = | ||
SendEmailRequest | ||
.builder() | ||
.destination(destination) | ||
.message(message) | ||
.source(sesConfig.sender) | ||
.build() | ||
|
||
try { | ||
sesClient.sendEmail(request) | ||
} catch (e: SesException) { | ||
logger.error(e) { "Failed to send email to $emailAddress with title $title and body $body" } | ||
throw e | ||
} | ||
} | ||
} |
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
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