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

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

Thanks for the help for the help.

+6
source share
2 answers

If you have a reference to an instance of Session , you can do the following:

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

If the mail client is connected to the corresponding SMTP server, it usually means that it is alive.

+6
source

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

From a connection point of view, you can just ping it:

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

Source: https://habr.com/ru/post/908515/


All Articles