diff --git a/src/main/kotlin/apply/infra/mail/AwsMailSender.kt b/src/main/kotlin/apply/infra/mail/AwsMailSender.kt index cf6a23071..3ba0a0d11 100644 --- a/src/main/kotlin/apply/infra/mail/AwsMailSender.kt +++ b/src/main/kotlin/apply/infra/mail/AwsMailSender.kt @@ -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 @@ -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!")