当前位置: 代码迷 >> Web前端 >> 剔除邮件
  详细解决方案

剔除邮件

热度:318   发布时间:2012-12-23 11:28:15.0
删除邮件

    public void deleteEmail() throws Exception {



        // 连接并打开邮箱

        Store store = session.getStore();
        try {
            store.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 定位收件箱
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);

        if (folder instanceof POP3Folder) {
            POP3Folder inbox = (POP3Folder) folder;
            Message[] messages = inbox.getMessages();
            for (int i = 0; i < messages.length; i++) {
                MimeMessage mimeMessage = (MimeMessage) messages[i];
                String uid = inbox.getUID(mimeMessage);

                // 判断数据库是否已经接受过当前邮件

                if (null != ) {
                    mimeMessage.setFlag(Flags.Flag.DELETED, true);
                }

            }
        } else if (folder instanceof IMAPFolder) {
            IMAPFolder inbox = (IMAPFolder) folder;
            Message[] messages = inbox.getMessages();
            for (int i = 0; i < messages.length; i++) {
                MimeMessage mimeMessage = (MimeMessage) messages[i];
                String uid = Long.toString(inbox.getUID(mimeMessage));

                // 判断数据库是否已经接受过当前邮件

                if (null != ) {
                    mimeMessage.setFlag(Flags.Flag.DELETED, true);
                }
            }
        }
        folder.close(true);
        store.close();
    }
?
  相关解决方案