Java Mail mystery - SMTP blocked?

后端 未结 6 1221
孤城傲影
孤城傲影 2020-12-09 05:40

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

6条回答
  •  死守一世寂寞
    2020-12-09 06:02

    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:

    1. Disable IPv6 on your Windows 7 box.
    2. Start your java program using this command line option:

      -Djava.net.preferIPv4Stack=true
      

    Doing either one of these will fix the problem.

提交回复
热议问题