Java 使用谷歌应用程序引擎发送电子邮件

Java 使用谷歌应用程序引擎发送电子邮件,java,google-app-engine,email,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 = "

我尝试使用谷歌应用程序引擎发送一封简单的电子邮件,其中包含此代码。 但是什么都没有发生,为了使用邮件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);

发件人应该是您自己的Gmail电子邮件地址,而不是
example@gmail.com


原因是SMTP服务器需要对您进行身份验证。

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

当在开发服务器中运行的应用程序调用邮件服务发送电子邮件消息时,该消息将打印到日志中。Java开发服务器不发送电子邮件消息

此外,发件人地址必须是(发件人)

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

除了电子邮件在本地主机上不起作用或由于发件人电子邮件不是经过身份验证的电子邮件之外,我还体验到,即使版本不是默认版本,电子邮件也不起作用。我在任何地方都找不到这个文件

例如:
非默认版本.myapp.appspot.com
(电子邮件不工作,没有错误日志)
myapp.appspot.com
(电子邮件有效)


请确认其他人是否也面临过此问题。

显然,GAE不再允许使用管理员帐户。您需要使用服务帐户:
project-id@appspot.gserviceaccount.com


我以前的项目仍然使用管理员帐户,但最近创建的项目不允许我使用任何管理员帐户。

所以没有办法从GAE项目发送电子邮件吗?或者只是不使用这种方式?您可以,只是从特定的地址和本地开发服务器只记录电子邮件到控制台