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));
source share