为什么 JavaMail 连接超时太长
2022-09-01 20:00:34
在我的应用程序中,我连接到服务器以对用户进行身份验证。这是代码:
try {
Properties prop = new Properties();
prop.put("mail.smtp.starttls.enable","true");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.connectiontimeout", 1000);
Session session = Session.getInstance(prop, null);
Transport transport = session.getTransport("smtp");
transport.connect("mion.elka.pw.edu.pl", 587, registerLog, registerPass);
transport.close();
return true;
} catch (NoSuchProviderException ex) {
Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch(AuthenticationFailedException ex) {
Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (MessagingException ex) {
Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
我将连接超时设置为1000 ms = 1s,但它被忽略。当我调试并设置错误的用户名和密码时,我捕获
javax.mail.MessagingException: java.net.SocketTimeoutException: Read timed out
不是在 1000 ms 之后,而是在 5000*60 ms = 5 min 之后
怎么了?如何减少超时?