2011-11-15 85 views
2

我经过这里的文件工作:App Engine和接收邮件

http://code.google.com/appengine/docs/java/mail/overview.html#Receiving_Mail_in_Java 

接收电子邮件。下面是我的Servlet:

package mailserver; 

import java.io.IOException; 
import java.util.Properties; 
import javax.mail.MessagingException; 
import javax.mail.Session; 
import javax.mail.internet.MimeMessage; 
import javax.servlet.http.*; 

public class MailHandlerServlet extends HttpServlet { 
    public void doPost(HttpServletRequest req, 
         HttpServletResponse resp) 
      throws IOException { 
     Properties props = new Properties(); 
     Session session = Session.getDefaultInstance(props, null); 
     MimeMessage message = null; 
     try { 
      message = new MimeMessage(session, req.getInputStream()); 
     } catch (MessagingException e) { 
      e.printStackTrace(); 
     } 

     resp.setContentType("text/plain"); 
     resp.getWriter().println(message); 
    } 
} 

我的AppEngine上的XML:

<?xml version="1.0" encoding="utf-8"?> 
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> 
    <application>myapp</application> 
    <version>4</version> 

<inbound-services> 
    <service>mail</service> 
</inbound-services> 

    <!-- 
    By default, App Engine sends requests serially to a given web server. 
    To allow App Engine to send multiple requests in parallel specify: 

     <threadsafe>true</threadsafe> 
    --> 

    <!-- Configure java.util.logging --> 
    <system-properties> 
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> 
    </system-properties> 

</appengine-web-app> 

而且在web.xml

<?xml version="1.0" encoding="utf-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> 
    <servlet> 
    <servlet-name>MailHandlerServlet</servlet-name> 
    <servlet-class>mailserver.MailHandlerServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>MailHandlerServlet</servlet-name> 
    <url-pattern>/_ah/mail/[email protected]</url-pattern> 
</servlet-mapping> 
<security-constraint> 
    <web-resource-collection> 
    <url-pattern>/_ah/mail/[email protected]</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
    <role-name>admin</role-name> 
    </auth-constraint> 
</security-constraint> 

</web-app> 

我的第一个问题,我还没有建立任何形式的额外电子邮件地址说:

接收传入的电子邮件在[email protected]地址

我认为这就像一个catchall和字符串可以是我喜欢的任何东西?

我的下一个问题是servlet会显示任何东西,如果它工作?目前我刚刚得到The requested URL /mailserver was not found on this server.

任何帮助入门将是伟大的。

TIA

回答

4

电子邮件消息被发送到由应用程序引擎生成的应用程式作为HTTP请求(POST)。 [email protected]是一般语法。 string是一些你可以选择的,例如对于特定的servlet映射url模式(路由到特定的servlet) - 在你的情况下,只有[email protected]将被MailHandlerServlet处理。

在此服务器上找不到请求的URL/mailserver。

我在代码中看不到该URL的映射。网址路径是/_ah/mail/url-pattern)。

如果HTTP调用/ servlet操作成功,您将获得HTTP状态码20X。