代码如下:
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.host", "imap.qq.com");
props.setProperty("mail.imap.port", "143");
// 创建Session实例对象
Session session = Session.getInstance(props);
// 创建IMAP协议的Store对象
Store store = session.getStore("imap");
// 连接邮件服务器
store.connect("12345676@qq.com", "123456");
// 获得收件箱
Folder folder = store.getFolder("INBOX");
// 以读写模式打开收件箱
folder.open(Folder.READ_WRITE);
// 获得收件箱的邮件列表
Message[] messages = folder.getMessages();
// 打印不同状态的邮件数量
System.out.println("收件箱中共" + messages.length + "封邮件!");
System.out.println("收件箱中共" + folder.getUnreadMessageCount() + "封未读邮件!");
System.out.println("收件箱中共" + folder.getNewMessageCount() + "封新邮件!");
System.out.println("收件箱中共" + folder.getDeletedMessageCount() + "封已删除邮件!");
执行 报错。。。。。
Exception in thread "main" javax.mail.AuthenticationFailedException: ??????????????????????¨??ssl?????ê?????÷???é??: http://service.mail.qq.com/cgi-bin/help?id=28
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:474)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:176)
at org.jhrcore.client.zhaopin.comm.IMAPReceiveMailTest.main(IMAPReceiveMailTest.java:55)
Java Result: 1
邮箱imap pop3服务都开启了
汪汪一只猫
开心每一天1111