【发布时间】:2018-03-30 17:01:48
【问题描述】:
我想从我的 GAE 项目中发送邮件。我已经按照文档示例...
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("xxx@xxxx.appspotmail.com", "Example.com Admin"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress("xxxxx@gmail.com", "Mr. User"));
msg.setSubject("Your Example.com account has been activated");
msg.setText("This is a test");
Transport.send(msg);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
部署后,我收到此异常消息
javax.mail.MessagingException:无法连接到 SMTP 主机:localhost,端口:25;
但是文档说:
当您创建 JavaMail Session 时,如果您不提供任何 SMTP 服务器配置,App Engine 将使用 Mail 服务发送消息
但它似乎尝试连接到 SMTP 服务器...显然 localhost 上没有 SMTP 服务器...
我从未使用过此服务...我的配额已满。
请帮帮我!
【问题讨论】:
-
您使用的是GAE提供的JavaMail吗?或者您是否在应用程序中包含 JavaMail jar 文件?
-
我正在使用我的应用程序中包含的 JavaMail jar。当我删除这个 jar 时,一旦部署了我的应用程序,就会出现“java.lang.NoClassDefFoundError: javax/mail/internet/AddressException”问题。我有“javax.mail.jar”。
标签: java google-app-engine smtp jakarta-mail