aws-ses-java无效日期



当我使用aws-ses发送电子邮件时,发生了一个异常,显示

com.amazonaws.AmazonServiceException:无效日期2015年12月14日星期一02:08:56+00:00。它必须在HTTP RFC 2616第3.3.1节(服务:AmazonSimpleEmailService;状态代码:400;错误代码:参数值无效;请求ID:e2716096-a207-11e5-9615-8135b4d7f5f9)

以下是我的代码:

public class SESEmailUtil {
    private final String accesskey = "XXXXXXXXX";
    private final String secretkey = "XXXXXXXXXXXXXXXX";
    private String REGION = "us-east-1";
    private Region region;
    private static AWSCredentials credentials;
    private static AmazonSimpleEmailServiceClient sesClient;
    private static SESEmailUtil sesEmailUtil = null;
    private SESEmailUtil() { 
        init(accesskey, secretkey);
    };
    public void init(String accesskey, String secretkey) {
        credentials = new BasicAWSCredentials(accesskey, secretkey);
        sesClient = new AmazonSimpleEmailServiceClient(credentials);
        region = Region.getRegion(Regions.fromName(REGION));
        sesClient.setRegion(region);
    }
    public static SESEmailUtil getInstance() {
        if (sesEmailUtil == null) {
            synchronized (SESEmailUtil.class) {
                return new SESEmailUtil();
            }
        } else {
            return sesEmailUtil;
        }
    }
    public void sendEmail(String sender, LinkedList<String> recipients,
            String subject, String body) {
        Destination destination = new Destination(recipients);
        try {
            Content subjectContent = new Content(subject);
            Content bodyContent = new Content(body);
            Body msgBody = new Body(bodyContent);
            Message msg = new Message(subjectContent, msgBody);
            SendEmailRequest request = new SendEmailRequest(sender,
                    destination, msg);
            SendEmailResult result = sesClient.sendEmail(request);
            System.out.println(result + "Email sent");
        } catch (Exception e) {
            e.printStackTrace();
            System.out
                    .println("Exception from EmailSender.java. Email not send");
        }
    }
}

public class TestSend {
    private static String sender = "";
    private static LinkedList<String> recipients = new LinkedList<String>();
    static final String BODY = "This email was sent through Amazon SES by using the AWS SDK for Java.";
    static final String SUBJECT = "Amazon SES test (AWS SDK for Java)";
    public static void main(String args[]) {
        SESEmailUtil sendUtil = SESEmailUtil.getInstance();
        String receive = "qinwanghao@XXXX.com.cn";
        recipients.add(receive);
        sendUtil.sendEmail(sender, recipients, SUBJECT, BODY);
    }
}   

该代码基于aws提供的示例。日期2015年12月14日星期一02:08:56+00:00无效,但在哪里可以修改格式?希望有人能帮我。THK.

Joda时间版本可能会出现问题。如果出现此错误,您应该使用maven(mvn-dependency:tree)检查依赖关系树。查找任何与aws-sdk提供的版本冲突的joda时间版本。要修复:将冲突版本的joda时间添加到pom.xml(或等效文件)中的排除项中。

最新更新