邮件服务 GAE 问题 - 发送邮件异常 "javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;"

Mail service GAE issue - sending mail exception "javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;"

我想从我的 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: Could not connect to SMTP host: localhost, port: 25;

但是文档说:

When you create a JavaMail Session, if you do not provide any SMTP server configuration, App Engine uses the Mail service for sending messages

但它似乎尝试连接到 SMTP 服务器...显然本地主机上没有 SMTP 服务器...

我从未使用过此服务...我的配额已满。

请帮帮我!

今天遇到了同样的问题。刚开始工作。 App Engine SDK 已包含 类 您需要发送电子邮件:

https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/mail/MailService.Message

那个和相关的类是调用邮件服务的方式。用这些替换您的消息 类,删除所有对 javax.mail 的引用。另一件事,如果你引用这个(就像我一样):

https://cloud.google.com/appengine/docs/standard/java/mail/sending-mail-with-mail-api

我无法让它工作,至少在没有 smtp 主机的情况下看起来不会。 google 很高兴在他们的示例代码库

中为 non-working 示例提供无意义的文档

此外,如果您遵循 "who can send mail" link,它会告诉您任何形式的地址 anything@[APP_NAME].appspotmail.com 或 anything@[APP_ALIAS].appspotmail.com 应该可以。使用我的应用程序名称导致 "unauthorized sender",但使用仪表板中的应用程序 ID 有效。本应是十分钟的解决方案变成了数小时的苦差事,但我有一个可以正常工作的电子邮件。谢谢,google。

演示如何发送邮件的Mail service API supports the JavaMail (javax.mail) interface which is included with the App Engine SDK. Using any other jars may create the issue. You may follow the code sample in Java 7 and Java 8

我应该注意,由于垃圾邮件问题,端口 25、465 和 587 上的出站连接是不允许的,因此邮件的发件人地址必须是 this link 中的选项之一。

您可以通过仪表板获取您的 application ID/name(与项目 ID/name 相同)。

请注意,Issue Tracker 保留用于报告错误和功能请求。如果您遇到与 APP_NAME 或 APP_ALIAS 相关的任何问题,建议在那里报告问题,以便我们能够深入研究问题。