【问题标题】:aws ses java Invalid dateaws ses java日期无效
【发布时间】:2016-03-19 10:55:05
【问题描述】:

当我使用 aws ses 发送电子邮件时发生了异常,这表明

com.amazonaws.AmazonServiceException: 无效日期 2015 年 12 月 14 日星期一 02:08:56 +00:00。它必须在其中之一 HTTP RFC 2616 第 3.3.1 节指定的格式(服务: 亚马逊简单电子邮件服务;状态码:400;错误代码: 无效参数值;请求编号: 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 提供的示例。 日期 Mon, 14 Dec 2015 02:08:56 +00:00 无效,但我在哪里可以修改格式? 希望有人可以帮助我。THK。

【问题讨论】:

  • 这是我在 HTTP RFC 2616 第 3.3.1 节中找到的一种允许格式“Sun, 06 Nov 1994 08:49:37 GMT”,但我不知道如何修改它
  • 让我困惑的是,我让代码在我同事的电脑上运行,emil可以发送OK。

标签: java email amazon-web-services amazon-ses


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-07-10
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多