2011-12-02 140 views
2

我在服務器上下面的代碼捉迷藏了GWT RPC:如何在gwt中獲取電子郵件的內容?

public class MailHandlerServlet extends HttpServlet{ 

public void doGet(HttpServletRequest req, HttpServletResponse resp) 
     throws IOException { 
    doPost(req, resp); 
} 

public void doPost(HttpServletRequest req, HttpServletResponse resp) 
     throws IOException { 
    Properties props = new Properties(); 
    Session session = Session.getDefaultInstance(props, null); 
    try { 
     MimeMessage message = new MimeMessage(session, req.getInputStream()); 
} catch (MessagingException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

我不知道解析MimeMessage功能。我如何獲得MimeMessage的內容?

這裏簡單的代碼,我寫的,但它不工作:

Object content = message.getContent(); 
if(content instanceof Multipart){ 
      Multipart mp = (Multipart)content; 
      int count3 = mp.getCount(); 
      for(int i = 0;i < count3;i++){ 
       BodyPart p = mp.getBodyPart(i); 
       if(p.isMimeType("text/plain")){ 
        TextBody data = (TextBody) p.getContent(); 
        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        data.writeTo(baos); 
        String datafull = new String(baos.toByteArray()); 
        PrintWriter out = resp.getWriter(); 
        out.print(datafull.toString()); 
       } 
+0

這不是GWT-RPC。你只需要分類HttpServlet,所以這與GWT無關。 – Renato

+0

您應該添加標籤'google-app-engine'。因爲這是您錯過提供的重要信息。目前還沒有包含GWT。 –

+0

我認爲這是關於你發佈「不工作」意味着什麼的時候。你有例外嗎?如果是,POST IT。 – Strelok

回答

相關問題