使用的是JavaMail
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
HashMap IAM = new HashMap();
//163网易会验证,需带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。
IAM.put("name","myname");
IAM.put("version","1.0.0");
IAM.put("vendor","myclient");
IAM.put("support-email","testmail@test.com");
Properties props = System.getProperties();
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
URLName urln = new URLName("imap", pmm.getPopHost(), pmm.getPort(), pmm.getFile(), pmm.getUsername(), pmm.getPassword());
IMAPStore store = (IMAPStore) session.getStore(urln);
store.connect();
store.id(IAM);
Folder folder = store.getFolder("已发送");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
System.out.println("Messages's length: " + message.length);