0
我有應用程序引擎應用程序。應用程序引擎郵件不發送
我有一個名爲的servlet推。我部署應用程序並調用我的servlet GET方法。
在我的servlet,我有兩個methind:
1)第一種是:(該方法不發送電子郵件我不已瞭解爲什麼我沒有錯誤)
void sendMail() throws UnsupportedEncodingException{
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
String msgBody = "TEXT HERE";
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("ownerMail","Example.com Admin"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]", "Mr. User"));
msg.setSubject("YOUR PDF HAVE PROBLEMS");
msg.setText(msgBody);
} catch (AddressException e) {
log("error", e);
} catch (MessagingException e) {
log("error", e);
}
}
我?調用另一個方法太:(這個作品!)
無效snedTest(){
String to = "somebody";
String from = "ownerMail";
String host = "localhost:8080";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
第一種方法不起作用!我不知道爲什麼?我在LOG中沒有錯誤。但第二種方法有效。