有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

smtp如何修复java中的“无法将socket转换为TLS”错误

我正在使用JavaMail API发送一封包含文本文件的电子邮件。我上周写的这段代码运行得非常好,但是我今天登录并运行了程序,在底部附加的图像中收到了错误。我更新到最新版本的Java8,但仍然收到这个错误。(我必须在项目中使用java 8进行工作)我查看了此次更新的java 8补丁说明,发现根CA证书已被删除,我不确定该怎么想/怎么做。我之所以发布这个问题,是因为我在其他关于这个问题的大量问题中找不到任何解决方案

我正在运行Java 8(jre 1.8.0_221),之前运行的是jre 1.8.0_211。我不知道发生了什么变化,因为它今天停止使用v.211,并且在我使用v.221更新到最新版本的Java8之后也不起作用。我尝试过其他各种属性,但都没有成功。我不确定这是否是Java删除了某些特定的东西(我对此表示怀疑),或者它是否与防火墙权限有关,也不确定我是否拥有smtp权限。无论如何,下面是电子邮件发送部分的代码,代码在Transport.send(message);失败,错误为“无法将socket转换为TLS”

                Properties props = new Properties();
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.host", host);
                props.put("mail.smtp.port", "25");
                props.put("mail.smtp.debug", "true");

                Session session = Session.getInstance(props, new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(smtpUsername, u2);
                    }
                });

                try {
                    Message message = new MimeMessage(session);
                    message.setFrom(new InternetAddress(from));
                    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
                    message.setSubject(prop.getProperty("Message"));

                    BodyPart messageBodyPart = new MimeBodyPart();
                    messageBodyPart.setText(prop.getProperty("Message"));

                    Multipart multipart = new MimeMultipart();
                    multipart.addBodyPart(messageBodyPart);

                    messageBodyPart = new MimeBodyPart();
                    DataSource source = new FileDataSource(prop.getProperty("text") + ".txt");
                    messageBodyPart.setDataHandler(new DataHandler(source));
                    messageBodyPart.setFileName(prop.getProperty("filename"));
                    multipart.addBodyPart(messageBodyPart);

                    message.setContent(multipart);

                    Transport.send(message);
                    System.out.println("Sent successfully.\n");

Error Message我收到了。希望我解释得足够透彻。这只是我在这里问的第二个问题。谢谢你的帮助


共 (1) 个答案