How to test that the mail server is alive with Java?

前端 未结 3 1996
长发绾君心
长发绾君心 2021-02-20 12:01

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 ?

Thanks by advance for your help.

3条回答
  •  情深已故
    2021-02-20 12:48

    From the JavaMail API, you could try sending an email and seeing if it was sent successfully.

    From a connectivity standpoint, you could just ping it:

      InetAddress host = InetAddress.getByName("mailserver");
      System.out.println("host.isReachable(1000) = " + host.isReachable(1000));
    

提交回复
热议问题