我正在使用JavaMail IMAP协议来处理来自Gmail的电子邮件。处理电子邮件时,javamail会给出NULL异常消息和以下堆栈跟踪:
DEBUG com.iot.std.listener.EmailListener - null com.sun.mail.imap.IMAPMessage.getProtocol(IMAPMessage.java:169) com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1546) com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:808) javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1502)
这会阻止我的电子邮件侦听器出现意外异常,但由于消息为NULL,我不知道它是什么异常。 这通常发生在消息数组末尾的600多封邮件中。 这是我的商店连接和文件夹打开代码:
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.imap.host", host);
props.put("mail.imap.port", "993");
props.put("mail.imap.starttls.enable", "true");
props.put("mail.imap.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.imap.socketFactory.fallback", "false");
props.put("mail.imap.socketFactory.port", "993");
Session session = Session.getInstance(props, null);
Store store = session.getStore("imaps");
store.connect(host,
ApplicationContextProvider.getApplicationBaseUrl().getAppianEmailMonitorUsername(),
ApplicationContextProvider.getApplicationBaseUrl().getAppianEmailMonitorPassword());
String folderToMonitor = "INBOX";
Folder folder = store.getFolder(folderToMonitor);
folder.open(Folder.READ_ONLY);
Message[] msgs = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));