我有以下代碼:問題與SES附件發送電子郵件
try{
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setSubject(emailSubjectTxt);
msg.setFrom(new InternetAddress(emailFromAddress));
msg.setRecipient(
Message.RecipientType.TO,
new InternetAddress("[email protected]"));
MimeMultipart mp = new MimeMultipart();
BodyPart part = new MimeBodyPart();
part.setContent(emailMsgTxt, "text/html");
mp.addBodyPart(part);
msg.setContent(mp);
MimeBodyPart attachment = new MimeBodyPart();
attachment.setFileName("SupportBySkill.pdf");
BufferedInputStream bis = new BufferedInputStream(
SendMail.class.getResourceAsStream("SupportBySkill.pdf"));
attachment.setContent(bis, "application/pdf");
mp.addBodyPart(attachment);
// Capture the raw message
ByteArrayOutputStream out = new ByteArrayOutputStream();
msg.writeTo(out);
RawMessage rm = new RawMessage();
rm.setData(ByteBuffer.wrap(out.toString().getBytes()));
ClientConfiguration cc = new ClientConfiguration();
cc.setHttpClientFactory(new HttpClientFactory() {
public HttpClient createHttpClient(ClientConfiguration config) {
return new DefaultHttpClient(new GAEConnectionManager(),
new BasicHttpParams());
}
});
// Set AWS access credentials
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(
new BasicAWSCredentials("XXXXXX",
"XXXXXX"), cc);
// Call Amazon SES to send the message
try {
client.sendRawEmail(new SendRawEmailRequest().withRawMessage(rm));
} catch (AmazonClientException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}catch(Exception e){e.printStackTrace();
log.severe("Could not send email. with error" + e.getMessage());
}
但是在谷歌應用程序引擎的代碼失敗,錯誤: 無法發送電子郵件。與errorno對象DCH MIME類型應用程序/ pdf
請告知可能是錯的。調試時出現此錯誤:
msg.writeTo(out);
,我能夠發送電子郵件,而不附件。 – Vik 2012-08-06 16:46:50