如何正确设置JavaMail超时设置 [英] How to properly set JavaMail timeout setting

查看:670
本文介绍了如何正确设置JavaMail超时设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaMail连接到POP3服务器.

I am using JavaMail to connect to a POP3 server.

此外,我设置了以下属性,以使JavaMail在电子邮件服务器不响应的情况下不会等待很长时间:

Further, I set the following properties, so that JavaMail won't wait to long if an email server doesn't respond:

props.setProperty("mail.pop3.connectionpooltimeout", "3000");
props.setProperty("mail.pop3.connectiontimeout", "3000");
props.setProperty("mail.pop3.timeout", "3000");

但是,在某些情况下,超时工作正常,但有时JavaMail冻结几分钟(!),并显示以下调试消息:

However, in some cases the timeout works properly but sometimes JavaMail freezes for minutes(!) with the following debug message:

DEBUG POP3: connecting to host "pop3.yahoo.com", port 110, isSSL false

更改端口或协议(SSL,TLS ..)无效.我认为主机根本不存在.

Changing ports or protocols (SSL, TLS..) has no effect. I assume that the host simply doesn't exist.

例如,如果我轮询pop3.yahoo.com而不是pop.mail.yahoo.com(这将是正确的主机名),则我必须等待很长时间,直到超时异常发生. 几分钟后,出现以下异常,应用程序继续运行:

For example, if I poll pop3.yahoo.com instead of pop.mail.yahoo.com (which would be the right host name), I have to wait very long til a timeout exception occurs. After several minutes, I get the following exception and the application continues to run:

java.net.ConnectException: Operation timed out

pop3.yahoo.com似乎存在,但不会回应:

pop3.yahoo.com seems to exist but won't respond:

localhost:~ me$ ping pop3.yahoo.com
PING pop3.yahoo.com (206.190.46.10): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
^C

您可能会问为什么我使用pop3.yahoo.com而不是pop.mail.yahoo.com. 好吧,我只是想测试如果我的应用程序的用户插入错误的主机名会发生什么情况.

You might be asking why I use pop3.yahoo.com instead of pop.mail.yahoo.com. Well, I simply wanted to test what happens if the user of my application inserts a wrong host name.

我认为此问题与该报告有关 http://www.opensubscriber.com/message/javamail-interest@java.sun.com/180946.html ,其中发布者声称,如果电子邮件服务器关闭连接,则会出现问题.然后,JavaMail似乎要等待很长时间(不知道为什么).

I believe that this issue is related to this report http://www.opensubscriber.com/message/javamail-interest@java.sun.com/180946.html where the poster claims that the problem occurs if the email server closes the connection. JavaMail then seems to wait very long (don't know why).

由于我发布的链接中的问题仍未得到解决:有人知道如何解决或至少调试此问题吗?

Since the issue wasn't resolved in the link I posted: Does somebody know how to fix or at least debug this?

任何帮助都会得到我们的赞赏!

Any help would be really appreciated!

推荐答案

我找到了问题的原因.这是我代码中的错误. Javamail遵守超时设置的规定.

I found the reason for the problem. It was a bug in my code. Javamail respects the timeout setting fine.

这篇关于如何正确设置JavaMail超时设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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