I have a Java program which uses javax.mail to send an SMTP message. This program works fine on a Linux box, I want to emphasize that beforehand. When I try this same cod
The problem is due to the IPv4/IPv6 preference of Java. Java tries to use IPv6 by default (?) and my ISP does not support IPV6. However, it's enabled on my Windows 7 boxes by default.
If you are experiencing similar behavior, you can verify this by going to "Control Panel/Network and Internet/Network Connections", right-clicking your internet connection, and selecting "Status" from the context menu. The Status dialog will display two lines similar to this:
IPv4 Connectivity: Internet
IPv6 Connectivity: No Internet access
This is the root of the problem - Java prefers IPv6, which it cannot use to connect to the internet.
To fix this, do either one (or both) of these things:
Start your java program using this command line option:
-Djava.net.preferIPv4Stack=true
Doing either one of these will fix the problem.