Skip to content

Commit

Permalink
feat: ses 메일 전송 실패시 java 메일을 통해 전송 시도 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Aug 16, 2024
1 parent 31c904d commit 526e41b
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ package com.few.email.sender.provider

import com.amazonaws.services.simpleemail.AmazonSimpleEmailService
import com.amazonaws.services.simpleemail.model.*
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Profile("prd")
@Component
class AwsSESEmailSendProvider(
private val amazonSimpleEmailService: AmazonSimpleEmailService,
private val javaEmailSendProvider: JavaEmailSendProvider,
) : EmailSendProvider {
private val log = KotlinLogging.logger {}
companion object {
private const val UTF_8 = "utf-8"
}

override fun sendEmail(form: String, to: String, subject: String, message: String) {
val destination = Destination().withToAddresses(to)
val sendMessage = Message()
Expand All @@ -25,6 +29,23 @@ class AwsSESEmailSendProvider(
.withMessage(sendMessage)
.withConfigurationSetName("few-configuration-set")

amazonSimpleEmailService.sendEmail(sendEmailRequest)
runCatching {
amazonSimpleEmailService.sendEmail(sendEmailRequest)
}.onFailure {
log.warn {
"Failed to send email using AWS SES. Falling back to JavaMailSender. Error: $it"
}
runCatching {
log.info {
"Sending email using JavaMailSender."
}
javaEmailSendProvider.sendEmail(form, to, subject, message)
}.onFailure {
log.error {
"Failed to send email using JavaMailSender."
}
throw it
}
}
}
}

0 comments on commit 526e41b

Please sign in to comment.