GAE - 当我部署应用程序不起作用,但在localhost上它有效吗?

时间:2012-07-20 15:24:05

标签: java eclipse google-app-engine

我使用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.UPDATE _

gae日志说:

  

java.lang.RuntimeException:javax.mail.SendFailedException:Send   失败(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!

3 个答案:

答案 0 :(得分:4)

发件人电子邮件地址有明显的限制。 Google App Engine文档提供了有关此内容的详细信息。

请参阅https://developers.google.com/appengine/docs/java/mail/overview#Sending_Mail

它会为您提供足够的选项供您考虑。

答案 1 :(得分:2)

mailapps@gmail.com是否有权使用您的申请?

答案 2 :(得分:1)

在控制台中转到 App Engine&gt;设置&gt;应用程序设置。将此电子邮件地址添加到授权发件人列表中。出现此问题是因为您从未经授权的电子邮件ID发送电子邮件。

  • 你是项目的拥有者并不重要,你必须这样做 在app引擎的应用程序设置中添加发件人电子邮件ID&gt;&gt; 设置

enter image description here