获取某一天的邮件:
` public static void main(String[] args) throws Exception {
Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.store.protocol", "imap"); props.put("mail.smtp.class", "com.sum.mail.smtp.SMTPTransport"); props.put("mail.imap.class", "com.sum.mail.imap.IMAPStore"); props.put("mail.smtp.host", "pop.163.com"); Session session = Session.getInstance(props); Store store = session.getStore("pop3"); store.connect("pop.163.com", "xxx", "xxx"); Folder folder = store.getFolder("inbox"); folder.open(Folder.READ_ONLY); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = simpleDateFormat.parse("2021-10-01"); Date date2 = simpleDateFormat.parse("2021-10-02"); SearchTerm comparisonTermGe = new SentDateTerm(DateTerm.GE, date); SearchTerm comparisonTermLt = new SentDateTerm(DateTerm.LT, date2); SearchTerm comparisonAndTerm = new AndTerm(comparisonTermGe, comparisonTermLt); Message[] messages = folder.search(comparisonAndTerm); System.out.println("你一共有" + messages.length + "封邮件"); System.out.println("=============================================="); for (int i = 0; i < messages.length; i++) { System.out.println("=============================================="); Message message = messages[i]; System.out.println("邮件主题" + message.getSubject()); System.out.println("发送日期" + message.getSentDate()); System.out.println("邮件内容" + message.getContentType()); //System.out.println("邮件内容2" + message.getContent()); } folder.close(false); store.close(); }`