4

我已经使用 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!

4

3 回答 3

4

发件人电子邮件地址有明确的限制。Google App Engine 文档提供了这方面的详细信息。

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

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

于 2012-07-20T17:20:00.780 回答
2

mailapps@gmail.com 是否有权访问您的应用程序?

于 2012-07-20T16:50:17.660 回答
2

在控制台中转到App Engine > Settings > Application Settings。将此电子邮件地址添加到授权发件人列表中。出现此问题是因为您从未经授权的电子邮件 ID 发送电子邮件。

  • 您是否是项目的所有者都没有关系,您必须在应用引擎的应用程序设置中添加发件人电子邮件 ID >> 设置

在此处输入图像描述

于 2016-06-16T06:33:10.530 回答