当我使用aws ses发送电子邮件异常时,显示我
com.amazonaws.AmazonServiceException: 无效日期星期一,2015年12月14日02:08:56 +00:00。它必须在其中一个 HTTP RFC 2616第3.3.1节规定的格式(服务: AmazonSimpleEmailService;状态代码:400;错误代码: InvalidParameterValue;请求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。
答案 0 :(得分:0)
Joda-time版本可能会出现问题。如果出现此错误,您应该使用maven(mvn dependency:tree)检查依赖树。寻找任何与aws-sdk提供的版本冲突的joda-time版本。修复:将joda-time的冲突版本添加到pom.xml中的排除项(或等效项)。