1
當我使用AWS SES發送電子郵件的例外發生這告訴我,AWS SES的java無效的日期
com.amazonaws.AmazonServiceException: 無效的日期星期一,2015年12月14日2時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 = "[email protected]";
recipients.add(receive);
sendUtil.sendEmail(sender, recipients, SUBJECT, BODY);
}
}
該代碼是基於由AWS所提供的示例。 日期2015年12月14日星期一02:08:56 +00:00無效,但我可以在哪裏修改格式? 希望有人能幫助我.THK。
這是允許的格式之一「Sun,1994年11月6日08:49:37 GMT」我在HTTP RFC 2616中找到3.3.1節,但我不知道如何修改它 –
讓我困惑的是我讓代碼在我的同事的計算機上運行,這個代碼可以發送OK。 –