<i id='JzKmy'><tr id='JzKmy'><dt id='JzKmy'><q id='JzKmy'><span id='JzKmy'><b id='JzKmy'><form id='JzKmy'><ins id='JzKmy'></ins><ul id='JzKmy'></ul><sub id='JzKmy'></sub></form><legend id='JzKmy'></legend><bdo id='JzKmy'><pre id='JzKmy'><center id='JzKmy'></center></pre></bdo></b><th id='JzKmy'></th></span></q></dt></tr></i><div id='JzKmy'><tfoot id='JzKmy'></tfoot><dl id='JzKmy'><fieldset id='JzKmy'></fieldset></dl></div>

      <tfoot id='JzKmy'></tfoot>
    1. <legend id='JzKmy'><style id='JzKmy'><dir id='JzKmy'><q id='JzKmy'></q></dir></style></legend>

      <small id='JzKmy'></small><noframes id='JzKmy'>

      • <bdo id='JzKmy'></bdo><ul id='JzKmy'></ul>

      1. Java Mail 之谜 - SMTP 被阻止?

        Java Mail mystery - SMTP blocked?(Java Mail 之谜 - SMTP 被阻止?)

          <legend id='TZqZZ'><style id='TZqZZ'><dir id='TZqZZ'><q id='TZqZZ'></q></dir></style></legend>
        • <i id='TZqZZ'><tr id='TZqZZ'><dt id='TZqZZ'><q id='TZqZZ'><span id='TZqZZ'><b id='TZqZZ'><form id='TZqZZ'><ins id='TZqZZ'></ins><ul id='TZqZZ'></ul><sub id='TZqZZ'></sub></form><legend id='TZqZZ'></legend><bdo id='TZqZZ'><pre id='TZqZZ'><center id='TZqZZ'></center></pre></bdo></b><th id='TZqZZ'></th></span></q></dt></tr></i><div id='TZqZZ'><tfoot id='TZqZZ'></tfoot><dl id='TZqZZ'><fieldset id='TZqZZ'></fieldset></dl></div>

                <bdo id='TZqZZ'></bdo><ul id='TZqZZ'></ul>
                  <tbody id='TZqZZ'></tbody>

                <small id='TZqZZ'></small><noframes id='TZqZZ'>

                  <tfoot id='TZqZZ'></tfoot>
                  本文介绍了Java Mail 之谜 - SMTP 被阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 javax.mail 发送 SMTP 消息的 Java 程序.这个程序在 Linux 机器上运行良好,我想事先强调一下.当我在我的 Windows 7 x64 机器上尝试相同的代码时,我收到了这个错误:

                  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 code on my Windows 7 x64 box, I get this error:

                  send failed, exception: javax.mail.MessagingException: Could not connect to SMTP host:     smtp.west.cox.net, port: 25;
                  nested exception is:  java.net.SocketException: Network is unreachable: connect
                  

                  代码如下:

                  Session session = Session.getInstance(props, null);
                  MimeMessage msg = new MimeMessage(session);
                  msg.setFrom();
                  msg.setRecipients(Message.RecipientType.TO, props.getProperty("mail.to", "me@mine.com"));
                  msg.setSubject(mySubject);
                  msg.setSentDate(new Date());
                  msg.setContent(sBuf.toString(), "text/html");
                  Transport.send(msg);
                  

                  这个程序几乎对所有东西都使用默认值.它在同一网络上的另一个盒子上工作正常.它使用的设置与我用于常规邮件客户端的设置相同,效果很好.这个 Windows 盒子上有一些东西阻止了 SMTP,但仅适用于 Java.

                  This program pretty much uses defaults for everything. It works fine on another box on the same network. It uses the same settings that I use for my regular mail client, which works fine. There is something on THIS Windows box that is blocking SMTP, but only for Java.

                  我安装了 Symantec (Norton) 360.关闭它没有任何区别,但重新启动到安全模式(几乎禁用所有东西)允许程序正常工作并发送邮件.

                  I have Symantec (Norton) 360 installed. Turning it off makes no difference, but rebooting into Safe Mode (which disables almost everything) allows the program to work and send mail just fine.

                  所以,回顾一下:

                  1. 程序代码有效.
                  2. 设置正确.
                  3. SMTP 适用于 Windows Mail,仅在此 Windows 计算机上被 Java 阻止.

                  在我又花一天时间拆开东西并卸载/重新安装之前,我想知道是否有人对解决此问题有任何建议?

                  Before I spend another day tearing things apart and uninstalling / reinstalling, I wondered if anyone had any advice on fixing this?

                  推荐答案

                  问题是由于 Java 的 IPv4/IPv6 偏好.Java 尝试默认使用 IPv6 (?) 而我的 ISP 不支持 IPV6.但是,默认情况下,它在我的 Windows 7 机器上启用.

                  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.

                  如果您遇到类似的行为,您可以通过转到控制面板/网络和 Internet/网络连接",右键单击您的 Internet 连接,然后从上下文菜单中选择状态"来验证这一点.状态对话框将显示两行类似的内容:

                  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
                  

                  这是问题的根源——Java 更喜欢 IPv6,它不能使用它来连接到 Internet.

                  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. 在您的 Windows 7 机器上禁用 IPv6.
                  2. 使用此命令行选项启动您的 java 程序:

                  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.

                  这篇关于Java Mail 之谜 - SMTP 被阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                  <legend id='GhjIr'><style id='GhjIr'><dir id='GhjIr'><q id='GhjIr'></q></dir></style></legend>
                  • <bdo id='GhjIr'></bdo><ul id='GhjIr'></ul>

                    <small id='GhjIr'></small><noframes id='GhjIr'>

                      <tbody id='GhjIr'></tbody>
                      <tfoot id='GhjIr'></tfoot>
                        1. <i id='GhjIr'><tr id='GhjIr'><dt id='GhjIr'><q id='GhjIr'><span id='GhjIr'><b id='GhjIr'><form id='GhjIr'><ins id='GhjIr'></ins><ul id='GhjIr'></ul><sub id='GhjIr'></sub></form><legend id='GhjIr'></legend><bdo id='GhjIr'><pre id='GhjIr'><center id='GhjIr'></center></pre></bdo></b><th id='GhjIr'></th></span></q></dt></tr></i><div id='GhjIr'><tfoot id='GhjIr'></tfoot><dl id='GhjIr'><fieldset id='GhjIr'></fieldset></dl></div>