首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

剔除邮件

2012-12-23 
删除邮件public void deleteEmail() throws Exception {// 连接并打开邮箱Store store session.getStore

删除邮件

    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();    }
?

热点排行