删除邮件

 Java代码 复制代码 收藏代码

  1. public void deleteEmail() throws Exception {
  2.  
  3.  
  4.  
  5. // 连接并打开邮箱
  6.  
  7. Store store = session.getStore();
  8. try {
  9. store.connect();
  10. } catch (Exception e) {
  11. e.printStackTrace();
  12. }
  13. // 定位收件箱
  14. Folder folder = store.getFolder("INBOX");
  15. folder.open(Folder.READ_WRITE);
  16.  
  17. if (folder instanceof POP3Folder) {
  18. POP3Folder inbox = (POP3Folder) folder;
  19. Message[] messages = inbox.getMessages();
  20. for (int i = 0; i < messages.length; i++) {
  21. MimeMessage mimeMessage = (MimeMessage) messages[i];
  22. String uid = inbox.getUID(mimeMessage);
  23.  
  24. // 判断数据库是否已经接受过当前邮件
  25.  
  26. if (null != ) {
  27. mimeMessage.setFlag(Flags.Flag.DELETED, true);
  28. }
  29.  
  30. }
  31. } else if (folder instanceof IMAPFolder) {
  32. IMAPFolder inbox = (IMAPFolder) folder;
  33. Message[] messages = inbox.getMessages();
  34. for (int i = 0; i < messages.length; i++) {
  35. MimeMessage mimeMessage = (MimeMessage) messages[i];
  36. String uid = Long.toString(inbox.getUID(mimeMessage));
  37.  
  38. // 判断数据库是否已经接受过当前邮件
  39.  
  40. if (null != ) {
  41. mimeMessage.setFlag(Flags.Flag.DELETED, true);
  42. }
  43. }
  44. }
  45. folder.close(true);
  46. store.close();
  47. }  
    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();
    }

你可能感兴趣的:(S)