1
我有好幾天試圖通過Google App Engine項目上的IMAP獲取消息的內容。使用javamail和IMAP的Google App Engine(GAE)message.getContent()不起作用
我設法提取所有其他信息,但要提取跳轉內容我錯誤消息(不工作,甚至調用message.getContent.tostring(),我試過MultiPart)。
我從一個正常的項目(不GAE和使用javamail.1.4.7)執行相同的操作,消息的內容完美顯示。
這是GAE項目的代碼:
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Session;
import java.io.IOException;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Store;
import javax.servlet.http.*;
@SuppressWarnings("serial")
public class nuevo extends HttpServlet {
private String User;
private String Pass;
private static final Logger log = Logger.getLogger(nuevo.class
.getName());
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
User = "User";
Pass = "Pass";
LlamaIMAP(resp);
}
public void LlamaIMAP(HttpServletResponse resp) {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.imap.host", "imap.gmail.com");
props.put("mail.imap.user", User);
props.put("mail.imap.socketFactory", 993);
props.put("mail.imap.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.imap.port", 993);
Session session = Session.getDefaultInstance(props,
new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(User, Pass);
}
});
try {
Store store = session.getStore("imap");
store.connect("imap.gmail.com", 993, User, Pass);
Folder fldr = store.getFolder("Inbox");
fldr.open(Folder.HOLDS_MESSAGES);
// HOLDS_MESSAGES);
Message[] ar = fldr.getMessages();
int count = fldr.getMessageCount();
resp.getWriter().println(count);
resp.getWriter().println(ar[0].getAllRecipients()[0].toString());
resp.getWriter().println(ar[0].getFrom()[0].toString());
resp.getWriter().println(ar[0].getSentDate().toString());
resp.getWriter().println(ar[0].getSubject());
resp.getWriter().println(ar[0].getContent().toString());
} catch (Exception exc) {
try {
resp.getWriter().println(exc + "error");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
「跳我錯誤信息」是什麼意思?什麼錯誤信息? [JavaMail調試輸出](http://www.oracle.com/technetwork/java/javamail/faq/index.html#debug)顯示什麼?另外,糾正你所做的[常見錯誤](http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes)。 –