0
我只是简单地按照教程中概述:https://cloud.google.com/solutions/mobile/firebase-app-engine-android-studio,部分添加后端模块。无法发送电子邮件在AppEngine教程
servlet代码我已经是:
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
static Logger Log = Logger.getLogger("com.example.username.myapplication.backend.MyServlet");
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
Log.info("Got cron message, constructing email.");
//Create a new Firebase instance and subscribe on child events.
Firebase firebase = new Firebase("[firebase-DB]");
firebase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Build the email message contents using every field from Firebase.
final StringBuilder newItemMessage = new StringBuilder();
newItemMessage.append("Hello main user");
//Now Send the email
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
//Make sure you substitute your project-id in the email From field
msg.setFrom(new InternetAddress("[email protected]",
"Todo Nagger"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]", "Recipient"));
msg.setSubject("Good Morning!");
msg.setText(newItemMessage.toString());
Transport.send(msg);
} catch (MessagingException | UnsupportedEncodingException e) {
Log.warning(e.getMessage());
}
}
public void onCancelled(FirebaseError firebaseError) {
}
});
}
}
而且cron.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/hello</url>
<description>Send me an email of outstanding items in the morning</description>
<schedule>every 1 minutes</schedule>
</cron>
</cronentries>
完成了在火力地堡后,AppEngine上仪表板并注册一个请求已经发生,但是,电子邮件永远不会发送,所有我在日志中看到的是错误:
Caused by: com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: The Socket API will be enabled for this application once billing has been enabled in the admin console.
尽管我已经为此应用启用了结算功能。
在开始使用计费之前是否有某种宽限期?
代码布局有什么问题?
哪里是日志,我找不到它们的服务器... – Sauron
https://console.cloud.google.com/logs –
此外,您可以将此页面允许的发件人列入白名单 - https:// console。 cloud.google.com/appengine/settings –