JavaMail API to iMail -- java.net.SocketException: Permission denied: connect

Add -Djava.net.preferIPv4Stack=true to the VM options. Another way to confirm if it is the same issue, in Netbeans, right click on the project > properties > Libraries and choose a JDK 6 Java Platform (install if you do not have it). Clean, build then try again. This will eliminate this issue as the problem

Credit https://stackoverflow.com/a/7478027/643500


In case to simplify app invocation (e.g. from CLI) used in the code at start:

System.setProperty("java.net.preferIPv4Stack", "true")

supposing that the app will be working with legacy IPv4 network stack.