java - 使用谷歌应用引擎发送电子邮件

标签 java google-app-engine email

我正在尝试使用谷歌应用引擎发送一封包含此代码的简单电子邮件。 但是没有任何反应,我必须配置一些东西才能使用邮件 api 吗? 这在本地主机上运行。 我使用 gmail 作为邮件主机。

   String host = "smtp.google.com";
String to = "example@yahoo.fr";
String from = "example@gmail.com";
String subject = "this is a test";
String messageText = "test";
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);

// Set debug on the Session
// Passing false will not echo debug info, and passing True will.

mailSession.setDebug(sessionDebug);

// Instantiate a new MimeMessage and fill it with the 
// required information.

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.

Transport.send(msg);

最佳答案

在本地运行 AppEngine 开发服务器时,实际上不会发送通过邮件服务发送的任何内容 - 它只会记录到控制台

参见 here

When an application running in the development server calls the Mail service to send an email message, the message is printed to the log. The Java development server does not send the email message.

此外,from地址必须是(来自here)

  • 应用管理员的电子邮件
  • 使用 Google 帐户登录的当前登录用户的电子邮件地址
  • 来自应用程序的有效电子邮件接收地址

关于java - 使用谷歌应用引擎发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10958191/

相关文章:

java - 循环添加 BigInteger java

java - 如何使用 spring 集成通过 POP3 标记已读消息?

java - 如何获取 Play Framework 2.2 (Java) 中的当前语言?

python - 在 Django 模板中从 JSON 中转义 html 实体

java - 视频文件转换/转码 Google App Engine

linux - 从邮件头解析发件人原始IP的Perl脚本

Java - AppleScript 的执行抛出 NullPointerException

java - 在开发中为 gae 应用程序抓取数据并将其上传到 prod 还是应该在 prod 中抓取更容易?

php - mail() - 电子邮件有效但短信无效

iphone - iOS 将字典从一个 plist 导入到另一个 plist