Skip to content

Commit

Permalink
feat: AWS 메일 기능 구현 확인
Browse files Browse the repository at this point in the history
  • Loading branch information
MyaGya committed Oct 10, 2021
1 parent e066565 commit 892410f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/kotlin/apply/infra/mail/AwsMailSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.nio.ByteBuffer
import java.util.Properties
import javax.activation.DataHandler
import javax.activation.DataSource
import javax.activation.MimetypesFileTypeMap
import javax.mail.Session
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeBodyPart
Expand Down Expand Up @@ -92,40 +93,40 @@ class AwsMailSender(
// Add the multipart/alternative part to the message.
msg.addBodyPart(wrap)
// Define the attachment
val att = MimeBodyPart()

// val fds: DataSource = ByteArrayDataSource(attachment, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") <- 레퍼런스
for ((fileName, fileData) in files) {
val fds: DataSource = ByteArrayDataSource(fileData.byteArray, "multipart/form-data")
val att = MimeBodyPart()
val fds: DataSource = ByteArrayDataSource(
fileData.byteArray,
MimetypesFileTypeMap().getContentType(fileName)
)
// val fds: DataSource = FileDataSource("C:\\Users\\kirin\\Desktop\\의문점 1.png")

att.dataHandler = DataHandler(fds)
att.fileName = fileName
// val reportName = "PhotoReport.xls" <- 이 항목이 있는걸로 보아 att.fileName으로 이름을 붙여줄 수 있는듯
// att.fileName = reportName
msg.addBodyPart(att)
}

// Add the attachment to the message.
msg.addBodyPart(att)

// Try to send the email.
try {
// println("Attempting to send an email through Amazon SES " + "using the AWS SDK for Java...")
val client =
AmazonSimpleEmailServiceClientBuilder.standard() // Replace US_WEST_2 with the AWS Region you're using for
// Amazon SES.
.withRegion(Regions.US_WEST_2).build() // 지역은 우선 건드리지 않음

// Print the raw email content on the console
// Print the raw email content on the console
val out = System.out
message.writeTo(out)

// Send the email.

// Send the email.
val outputStream = ByteArrayOutputStream()
message.writeTo(outputStream)
val rawMessage = RawMessage(ByteBuffer.wrap(outputStream.toByteArray()))

val rawEmailRequest = SendRawEmailRequest(rawMessage)
.withConfigurationSetName("ConfigSet") // <- 기본값
// .withConfigurationSetName("ConfigSet") // <- 기본값

client.sendRawEmail(rawEmailRequest)
// println("Email sent!")
Expand Down

0 comments on commit 892410f

Please sign in to comment.