我正在尝试使用 Java SDK 2 通过 AWS SES 发送电子邮件。尽管我能够成功发送电子邮件。我想知道如何在 Java SDK 2 中发送电子邮件时设置配置集。
我正在尝试遵循类似于 AWS 文档中提供的代码,但它没有指定如何将配置集添加到电子邮件请求对象。
/* EMAIL MESSAGE BODY SETUP */
System.out.println("Attempting to send an email through Amazon SES " + "using the AWS SDK for Java...");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.writeTo(outputStream);
ByteBuffer buf = ByteBuffer.wrap(outputStream.toByteArray());
byte[] arr = new byte[buf.remaining()];
buf.get(arr);
SdkBytes data = SdkBytes.fromByteArray(arr);
RawMessage rawMessage = RawMessage.builder()
.data(data)
.build();
SendRawEmailRequest rawEmailRequest = SendRawEmailRequest.builder()
.rawMessage(rawMessage)
.build();
client.sendRawEmail(rawEmailRequest);
需要帮助将配置集添加到rawEmailRequest
AWS Java SDK 1 指定了代码示例中配置集的使用。(以下)
AmazonSimpleEmailService client =
AmazonSimpleEmailServiceClientBuilder.standard()
// Replace US_WEST_2 with the AWS Region you're using for
// Amazon SES.
.withRegion(Regions.US_WEST_2).build();
SendEmailRequest request = new SendEmailRequest()
.withDestination(
new Destination().withToAddresses(TO))
.withMessage(new Message()
.withBody(new Body()
.withHtml(new Content()
.withCharset("UTF-8").withData(HTMLBODY))
.withText(new Content()
.withCharset("UTF-8").withData(TEXTBODY)))
.withSubject(new Content()
.withCharset("UTF-8").withData(SUBJECT)))
.withSource(FROM)
// Comment or remove the next line if you are not using a
// configuration set
.withConfigurationSetName(CONFIGSET);
client.sendEmail(request);
感谢您的帮助!!