jvamail中MessageCountListener()的getsubject调用不了
public static void update() throws MessagingException {
        // 准备链接服务器的会话信息
        Properties props = new Properties();
        props.setProperty("mail.store.protocol", "imap");
        props.setProperty("mail.imap.host", "imap.sina.com");
        props.setProperty("mail.imap.port", "143");

        // 创建session实例对象
        Session session = Session.getInstance(props);
        session.setDebug(true);

        // 创建IMAP协议的Store对象
        Store store = session.getStore("imap");

        // 链接邮件服务器
        store.connect("××××@sina.com", "××××××");
        System.out.println("连上了");

        // 获得邮件收件箱
        Folder folder = store.getFolder("INBOX");
        // 以读写模式打开收件箱
        folder.open(Folder.READ_WRITE);

        folder.addMessageCountListener(new MessageCountListener() {
            public void messagesRemoved(MessageCountEvent messagecountevent) {
            }

            @Override
            public void messagesAdded(MessageCountEvent ev) {
                System.out.println("new message");
                Message[] msgs = ev.getMessages();
                for (int i = 0; i < msgs.length; i++) {
                    System.out.println(msgs[i].getMessageNumber());
                    try {
                        System.out.println("========");
                        System.out.println("***1"+msgs[i].toString());
                        System.out.println("***2"+(msgs[i]==null));
                        System.out.println("***3:"+msgs[i].getSubject().toString());
                        System.out.println("***4:"+msgs[i].getFrom().toString());
                    } catch (MessagingException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        boolean supportIDLE = false;
        try {
            if (folder instanceof IMAPFolder) {
                IMAPFolder f = (IMAPFolder) folder;
                f.idle();
                supportIDLE = true;
            }
        } catch (FolderClosedException fex) {
            update();
        } catch (MessagingException mex) {
            supportIDLE = false;
        }

控制台输出截取如下:


========
***1com.sun.mail.imap.IMAPMessage@7b80f885
***2false
DONE
A2 OK IDLE completed
A3 FETCH 24 (ENVELOPE INTERNALDATE RFC822.SIZE)

就是在这里我就是调用不起来getsubject方法。没法取这个信

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐