//获取邮箱会话
@NotNull
private static Session getMailSession() {
Properties prop = System.getProperties();
prop.put("mail.imap.host", "imaphz.qiye.163.com");
prop.put("mail.imap.auth.plain.disable", "true");
prop.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); //使用JSSE的SSL socketfactory来取代默认的socketfactory
prop.put("mail.imap.socketFactory.fallback", "false"); // 只处理SSL的连接,对于非SSL的连接不做处理
prop.put("mail.imap.port", 143);
prop.put("mail.imap.socketFactory.port", 993);
Session mailSession = Session.getInstance(prop, null);
return mailSession;
}
Session mailSession = getMailSession();
IMAPStore store = null;
IMAPFolder folder = null;
// 使用IMAP方式进行连接
store = (IMAPStore) mailSession.getStore("imap");
//user参数为邮箱信息***@.com,password为自己的激活码(需要再自己去网易企业邮箱进行认证和获取)
store.connect(imapServer, user, password);
// 拿到收件箱
folder = (IMAPFolder) store.getFolder("INBOX");