微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么JavaMail连接超时太长

在我的应用程序中,我连接到服务器来验证用户.这是代码
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,ex);
        return false;
    } catch (MessagingException ex) {
        Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,ex);
        return false;
    }

我将连接超时设置为1000 ms = 1s,但忽略.当我调试并设置错误用户名和密码我抓住

javax.mail.MessagingException: java.net.socketTimeoutException: Read timed out

不是在1000 ms后,但在5000 * 60 ms = 5分钟后

哪里不对 ?我如何减少时间?

解决方法

您还可以设置Socket I / O超时.当连接但未能从服务器读取数据时,它将继续等待.
prop.put("mail.smtp.timeout",1000);

读取超时表示您已连接,但无法从服务器读取数据.

原文地址:https://www.jb51.cc/java/125825.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐