我已经使用 app 编写了一个 gae 引擎 java mail api。
我的 appengine-web.xml:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>mailapps</application>
<version>1</version>
<!--
Allows App Engine to send multiple requests to one instance in parallel:
-->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<!--
HTTP Sessions are disabled by default. To enable HTTP sessions specify:
<sessions-enabled>true</sessions-enabled>
It's possible to reduce request latency by configuring your application to
asynchronously write HTTP session data to the datastore:
<async-session-persistence enabled="true" />
With this feature enabled, there is a very small chance your app will see
stale session data. For details, see
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
-->
</appengine-web-app>
当我在 localhost 上运行该应用程序时,我一切正常,但是当我在 gae 上运行部署它并运行它时,我得到:
错误:服务器错误 服务器遇到错误,无法完成您的请求。
如果问题仍然存在,请报告您的问题并提及此错误消息和导致它的查询。
我的应用程序有什么问题?你能帮我么?
1.更新_
盖伊日志说:
java.lang.RuntimeException:javax.mail.SendFailedException:发送失败(javax.mail.MessagingException:非法参数(java.lang.IllegalArgumentException:未经授权的发件人:未经授权的发件人))
2.更新
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class FeedbackServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(FeedbackServlet.class.getName());
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String description = req.getParameter("description");
String email = req.getParameter("email");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
log.info(description + name + email + " :Daten extrahiert!");
String msgBody = name + " :Name der Person" + "\n" + description + " :Beschreibung der Person" + "\n" + email + " :EMAIL";
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("mailapps@gmail.com",
"It works"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("maximus@gmail.com", "Your name"));
msg.setSubject("Bestellung");
msg.setText(msgBody);
log.info("Message send!");
Transport.send(msg);
} catch (Exception e) {
resp.setContentType("text/plain");
resp.getWriter().println("Something went wrong. Please try again.");
throw new RuntimeException(e);
}
resp.setContentType("text/plain");
resp.getWriter().println(
"Thanks you for your feedback. An Email has been send out.");
}
}
那是servlet!