gpt4 book ai didi

java - GAE - 当我部署应用程序时不起作用,但在本地主机上它有效吗?

转载 作者:搜寻专家 更新时间:2023-11-01 01:45:38 26 4
gpt4 key购买 nike

我已经使用应用程序编写了一个 gae 引擎 java 邮件 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>

当我在本地主机上运行应用程序时,一切正常,但是当我在 gae 上运行部署并运行时,我得到:

Error: Server Error The server encountered an error and could not complete your request.

If the problem persists, please report your problem and mention this error message and the query that caused it.

我的应用有什么问题?你能帮帮我吗?

1.UPDATE_

gae 日志说:

java.lang.RuntimeException: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Illegal Arguments (java.lang.IllegalArgumentException: Unauthorized Sender: Unauthorized sender))

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!

最佳答案

发件人Email Address有明确的限制。 Google App Engine 文档提供了这方面的详细信息。

引用https://developers.google.com/appengine/docs/java/mail/overview#Sending_Mail

它会给你足够的选择,你可以考虑。

关于java - GAE - 当我部署应用程序时不起作用,但在本地主机上它有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com