amazon-web-servicesamazon-sesaws-java-sdk-2.x

Non-ascii email address with Java & AWS SES


I'm using AWS SES to send emails from a Java application using AWS SDK v2.
ASCII email addresses work fine (myemail@gmail.com), but when I try to send email to address with non-ascii characters (myemail+早上@gmail.com or myemail+й@gmail.com), I don't receive anything.

Here is my code:

import jakarta.mail.internet.InternetAddress
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.ses.SesClient
import software.amazon.awssdk.services.ses.model.SendEmailRequest
import java.net.IDN
import java.nio.charset.StandardCharsets.UTF_8


val ses = SesClient.builder()
  .region(Region.US_EAST_1)
  .build()

val email1 = IDN.toASCII("myemail@gmail.com", IDN.ALLOW_UNASSIGNED) // works fine
val email2 = IDN.toASCII("myemail+早上@gmail.com", IDN.ALLOW_UNASSIGNED) // no exception but email is not received
val email3 = IDN.toASCII("myemail+й@gmail.com", IDN.ALLOW_UNASSIGNED) // no exception but email is not received
ses.sendEmail(
  SendEmailRequest.builder()
    .destination { it.toAddresses(email1, email2, email3) }
    .message { messageBuilder ->
      messageBuilder
        .subject { it.data("Test").charset(UTF_8.toString()) }
        .body { bodyBuilder ->
          bodyBuilder
            .html { it.data("<h1>Hello</h1>").charset(UTF_8.toString()) }
            .text { it.data("Hello").charset(UTF_8.toString()) }
        }
    }
    .source(InternetAddress("myemail@gmail.com", "My Email", UTF_8.toString()).toString())
    .build()
)

Any idea?


Solution

  • AWS SES only supports 7-bit ASCII in the local part of the email address (i.e. before the @), according to their docs.