Warm tip: This article is reproduced from serverfault.com, please click

smtp-Java Mailing Logic:无法将套接字转换为TLS

(smtp - Java Mailing Logic: Could not convert socket to TLS)

发布于 2013-06-25 11:18:19

在一个应用程序中,我使用Java实现了邮件发送逻辑。我用smtp.gmail.com587 port有效的gmail ID和密码。在开发环境中,一切正常。但是,在生产环境中,我需要使用不同的邮件服务器说,smtp.xyz.inport 25与该域上的一个有效的电子邮件ID和密码。

当我继续使用以下代码启用SSL时:

我收到一个错误

Could not convert socket to TLS

SunCertPathBuilderException: Unable To Find Valid Certification Path To Requested Target

================================================== =====

final ResourceBundle rsbd=ResourceBundle.getBundle("main/ResourceBundle/Dyna");

        // -- Attaching to default Session, or we could start a new one                                            

                    props.put("mail.smtp.host", smtpServer);

                props.put("mail.smtp.auth", "true");

                props.put("mail.debug", "true");

            props.put("mail.smtp.port", port); 

                props.put("mail.smtp.starttls.enable","true");

            props.put("mail.smtp.EnableSSL.enable","true");

  Session session =Session.getInstance(props, new Authenticator() {protected PasswordAuthentication getPasswordAuthentication() {return new PasswordAuthentication(admin_mail, admin_password);}});

         // -- Create a new message --
      Message msg = new MimeMessage(session);

     // -- Set the FROM and TO fields --
      msg.setFrom(new InternetAddress(from));

      msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));

      msg.setSubject(subject);
      msg.setText(emailContent);

      // -- Set some other header information --
      msg.setHeader("X-Mailer", "LOTONtechEmail");
      msg.setSentDate(new Date());

        // -- Send the message --
        Transport.send(msg);

当我删除EnableSSL并尝试添加以下代码时:

(getting javax.mail.AuthenticationFailedException:535 5.7.3 Authentication unsuccessful)

================================================== ========================

props.put("mail.smtp.socketFactory.port","25");

  props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

  props.put("mail.smtp.socketFactory.fallback", "true");


  MailSSLSocketFactory sf=new MailSSLSocketFactory();

  sf.setTrustAllHosts(true);

  props.put("mail.smtp.ssl.socketFactory", sf);

通过在过去3天内进行足够的Google搜索,我了解到我需要像这里给出的那样配置受信任的证书

但我想继续进行而不进行加密,也不必进行抢劫来启用SSL。有没有一种方法可以通过Java程序通过我们自己的域发送电子邮件而无需启用SSL。任何帮助将不胜感激。

Questioner
Shailesh Saxena
Viewed
0
Bill Shannon 2013-06-26 01:20:47

邮件服务器控制是否需要SSL / TLS。如果需要它,则必须使用它。

你可以将mail.smtp.ssl.trust属性设置为忽略证书问题,也可以按照JavaMail FAQ中的说明进行修复