最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Non-ascii email address with Java & AWS SES - Stack Overflow

programmeradmin7浏览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 or myemail+й@gmail), 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.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", IDN.ALLOW_UNASSIGNED) // no exception but email is not received
val email3 = IDN.toASCII("myemail+й@gmail", 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?

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 or myemail+й@gmail), 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.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", IDN.ALLOW_UNASSIGNED) // no exception but email is not received
val email3 = IDN.toASCII("myemail+й@gmail", 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?

Share Improve this question asked Mar 24 at 13:51 Cedric ThiebaultCedric Thiebault 1,0271 gold badge16 silver badges28 bronze badges 3
  • Did you check ses logs? – Daniel A. White 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
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论