为什么JavaMail连接超时太长 [英] Why JavaMail connection timeout is too long

查看:388
本文介绍了为什么JavaMail连接超时太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我连接到服务器以验证用户身份。这是代码:

In my application I connect to server to authenticate users. This is code:

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但忽略它。当我调试并设置错误的用户名和密码时,我会抓住

I set connection timeout to 1000 ms = 1s but it's ignore. When i debug and set wrong username and password i catch

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

不是在1000毫秒之后,而是在5000 * 60毫秒= 5分钟之后

not after 1000 ms, but after 5000*60 ms = 5 min

有什么问题?我如何减少时间?

What is wrong ? How can i reduce timeoute ?

推荐答案

我通过更改到最新版本的JavaMail(到JavaMail 1.5)解决了我的问题。我在那里写到: http://openejb.979440 .n4.nabble.com /哪个版本的JavaMail-td4665285.html

I resolve my problem by changing to the newest version of JavaMail (to JavaMail 1.5). I write about it there: http://openejb.979440.n4.nabble.com/Which-version-of-JavaMail-td4665285.html

感谢所有人的帮助,特别是对比尔香农:)

thank's everybody for help, specially to Bill Shannon :)

这篇关于为什么JavaMail连接超时太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆