You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWS Java SDK调用Amazon Pinpoint发邮件报错求助:需包含邮件消息

Hey Steve, let's work through this Pinpoint issue you're facing—I’ve dealt with similar headaches before, so here’s what you need to check to fix that "must include an email message" error:

Fixing the "Must Include an Email Message" Error in Amazon Pinpoint (Java SDK)

This error almost always boils down to missing or misconfigured email content in your DirectMessageConfiguration, even if your endpoint and verified email look good. Pinpoint requires explicit, valid email content to trigger a send.

Key Checks to Resolve the Issue

  • Ensure EmailMessage has required fields: Pinpoint mandates at least a Subject AND either a plain-text or HTML body. Empty values here will trigger the error.
  • Properly link EmailMessage to DirectMessageConfiguration: You have to explicitly attach your built email content to the direct message configuration—this is the most commonly missed step.

Full Working Code Example

Here’s a complete Java snippet that follows Pinpoint’s requirements for direct email sends:

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.pinpoint.PinpointClient;
import software.amazon.awssdk.services.pinpoint.model.*;
import java.util.Map;

public class PinpointDirectEmailSender {
    public static void main(String[] args) {
        // Replace these with your actual values
        String pinpointAppId = "YOUR_PINPOINT_APPLICATION_ID";
        String targetEndpointId = "YOUR_VALIDATED_ENDPOINT_ID";

        // Initialize Pinpoint client
        PinpointClient pinpointClient = PinpointClient.builder()
                .region(Region.US_EAST_1) // Swap with your AWS region
                .build();

        // Build the core email content
        EmailMessage emailContent = EmailMessage.builder()
                .subject(EmailContent.builder().data("Test Direct Email from Pinpoint").build())
                .body(EmailBody.builder()
                        .text(EmailContent.builder().data("This is a test message sent via AWS Java SDK.").build())
                        // Optional: Add HTML body if needed
                        //.html(EmailContent.builder().data("<h1>HTML Test Content</h1>").build())
                        .build())
                .build();

        // Configure direct message to use the email content
        DirectMessageConfiguration directMsgConfig = DirectMessageConfiguration.builder()
                .emailMessage(emailContent) // Critical: Don't skip this line!
                .build();

        // Assemble the send request
        SendUsersMessageRequest sendRequest = SendUsersMessageRequest.builder()
                .applicationId(pinpointAppId)
                .sendUsersMessageConfiguration(SendUsersMessageConfiguration.builder()
                        .directMessageConfiguration(directMsgConfig)
                        .users(Map.of(targetEndpointId, EndpointSendConfiguration.builder().build()))
                        .build())
                .build();

        // Execute the send
        try {
            SendUsersMessageResponse response = pinpointClient.sendUsersMessage(sendRequest);
            System.out.println("Message sent successfully! ID: " + response.messageId());
        } catch (PinpointException e) {
            System.err.println("Error details: " + e.awsErrorDetails().errorMessage());
            System.exit(1);
        } finally {
            pinpointClient.close();
        }
    }
}

Common Mistakes to Avoid

  1. Forgot to attach emailMessage: If your DirectMessageConfiguration is initialized without linking the EmailMessage, Pinpoint won’t recognize any email content—this is the #1 cause of this error.
  2. Empty content values: A blank subject or empty body text/HTML will trigger the same error. Double-check that your content strings have actual text.
  3. Wrong message type: Accidentally setting smsMessage instead of emailMessage (or vice versa) will make Pinpoint ignore your email content entirely.

If you still run into issues after adjusting for these points, verify you’re using the latest AWS Java SDK v2, and that your IAM role has the mobiletargeting:SendUsersMessages permission.

内容的提问来源于stack exchange,提问作者Steve

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:16:22