private static Session getSession() { Properties props = new Properties(); props.put("mail.smtp.host", HOST);//设置服务器地址 props.put("mail.store.protocol" , PROTOCOL);//设置协议 props.put("mail.smtp.port", PORT);//设置端口
以下代码加在这个附近就行
props.put("mail.smtp.ssl.enable", true);props.put("mail.smtp.auth" , true); /* Authentication authentication = new Authentication(userName, userPwd); Session session = Session.getDefaultInstance(props,authentication);*/ Authenticator authenticator = new Authenticator() {
@Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(FROM, PWD); }
}; //Authenticator authentication = new Authenticator("13631785646@136.com", "admin671435..."); Session session = Session.getDefaultInstance(props , authenticator);
return session; }
将465端口改为25端口