Java Mail timeout&连接超时处理 [英] Java Mail timeout & connectiontimeout handling
问题描述
我想将mail.smtp.connectiontimeout和mail.smtp.timeout属性。
以编程方式,我想在超时和/或 connectiontimeout 操作在Java中实现并相应处理事情。处理这个意义上,我需要在下次再次重试相同的电子邮件。
如何在Java / JavaMail中处理这个?是否可以抓住&处理这个超时操作?
编辑
另外,是否可以模拟假设我对SMTP服务器有完整的管理权限,我自己再次执行这个超时操作?
回答你的第二个问题:在您的测试机器上,只需使用iptables将与SMTP服务器的所有传出连接全部删除:
iptables -I OUTPUT 1 -p tcp -s 192.168.1.20 --dport 25 -j DROP
这样它看起来像一个无响应的smtp服务器,你可以测试你的异常处理。
I'm using JavaMail to send email requests to an SMTP server.
I would like to set both "mail.smtp.connectiontimeout" and "mail.smtp.timeout" properties within my code.
Programmatically, I want to catch both when timeout and/or connectiontimeout operations are reached in Java and handle things accordingly. Handling in the sense, I need to retry the same email once again the next time.
How do I handle this in Java/JavaMail? Is it possible to catch & handle this timeout operations?
EDIT
Also, is it possible to simulate/reproduce this timeout operation on my own assuming I've complete administration access to the SMTP server?
Answering your second question: On your test machine just DROP all outgoing connections to your SMTP Server with iptables:
iptables -I OUTPUT 1 -p tcp -s 192.168.1.20 --dport 25 -j DROP
This way it does look like an unresponsive smtp server and you can test your exception handling.
这篇关于Java Mail timeout&连接超时处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!