Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在端口465连接到smtp.gmail.com_Java_Smtp_Gmail - Fatal编程技术网

Java 无法在端口465连接到smtp.gmail.com

Java 无法在端口465连接到smtp.gmail.com,java,smtp,gmail,Java,Smtp,Gmail,我正在开发一个应用程序,其中我必须通过java代码发送邮件。我使用smtp.gmail.com作为服务器和端口465(也尝试了25和567)。同样的代码在我朋友的系统上运行良好。但在我的系统中,它显示出异常。即使是telnet smtp.gmail.com 465也无法连接。请提供帮助防火墙?代理哪个异常?请查看异常的堆栈跟踪,它将提到问题。javax.mail.MessaginException:无法连接到SMTP主机:localhost,端口:465。。。这是我得到的例外。。。我在命令提示符

我正在开发一个应用程序,其中我必须通过java代码发送邮件。我使用smtp.gmail.com作为服务器和端口465(也尝试了25和567)。同样的代码在我朋友的系统上运行良好。但在我的系统中,它显示出异常。即使是telnet smtp.gmail.com 465也无法连接。请提供帮助

防火墙?代理哪个异常?请查看异常的堆栈跟踪,它将提到问题。javax.mail.MessaginException:无法连接到SMTP主机:localhost,端口:465。。。这是我得到的例外。。。我在命令提示符下尝试了telnet smtp.gmail.com 465…它也给出了“连接失败”错误您可能需要在端口465和567上使用SSL。我做到了,同样的代码在我朋友的系统中运行良好…我该怎么办。。。
final String from = "aijopc@gmail.com";
            final String password = "aijopc@123";
            String host = "smtp.gmail.com";
            Properties props = System.getProperties();
            props.put("mail.host", host);
            props.put("mail.user", from);
            props.put("mail.smtp.password", password);
            props.put("mail.defaultEncoding", "UTF-8");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.required", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.socketFactory.fallback", "true");
            props.put("mail.smtp.port", "587");
            props.put("mail.smtp.socketFactory.port", "587");
            // props.setProperty("mail.transport.protocol", "smtp");

            props.setProperty("mail.smtp.ssl.trust", host);