网上找了有说这样写的
Session session;
try {
session = Session.getDefaultInstance(props);
} catch (Exception e) {
session = Session.getInstance(props);
}
但其实仍然会报发送失败的错误;
正确的应该这样改,重新验证一下
Session session = Session.getDefaultInstance(props, new Authenticator() {
//身份认证
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(emailConfig.getString("email"), emailConfig.getString("password"));//fromUser(), fromUserPassword
}
});