如何使用Java测试邮件服务器是否还存在? [英] How to test that the mail server is alive with Java?

查看:49
本文介绍了如何使用Java测试邮件服务器是否还存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JavaMail API是否可以检查所使用的邮件服务器是否处于活动状态? 如果没有,该如何使用Java代码进行处理?

Is there a way with JavaMail API to check that the mail server used is alive ? If not, how do to it with Java code ?

在此先感谢您的帮助.

推荐答案

如果您引用了

If you've got a reference to a Session instance, you could do the following:

Session s = //a JavaMail session I got from somewhere
boolean isConnected = s.getTransport("smtp").isConnected();

如果邮件客户端已连接到适当的SMTP服务器,则通常表示它仍处于活动状态.

If the mail client is connected to the appropriate SMTP server, it usually means it's alive.

这篇关于如何使用Java测试邮件服务器是否还存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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