0

I'm using AWS SES to send emails from a Java application using AWS SDK v2.
ASCII email addresses work fine ([email protected]), 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("[email protected]", 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("[email protected]", "My Email", UTF_8.toString()).toString())
    .build()
)

Any idea?

3
  • Did you check ses logs? Commented Mar 24 at 13:58
  • IDB.toUnicode would be the alternative. Try "myemail+\[email protected]" to check source code encoding. Maybe all after + is ignored but still fails if not ASCII.. Seems a bug w.r.t. IDN_ALLOW_UNASSIGNED.
    – Joop Eggen
    Commented Mar 24 at 14:12
  • 1
    AFAICT, you're probably encoding incorrectly. Only the domain name is meant to go through conversion. Your passing of the whole string through it likely corrupts the actual local name (i.e. everything left of +). I'd suggest checking the resulting conversions. Also note that the SES documentation states no Unicode support and no Punycode in the local part of the address.
    – Hasturkun
    Commented Mar 24 at 15:13

1 Answer 1

1

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.