Java Mailing Logic:无法将套接字转换为TLS [英] Java Mailing Logic: Could not convert socket to TLS

查看:712
本文介绍了Java Mailing Logic:无法将套接字转换为TLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个应用程序中,我使用java实现了邮件发送逻辑。我使用有效的Gmail密码和密码,使用 smtp.gmail.com 超过 587端口。在开发环境中,一切正常。但在生产环境中,我需要使用不同的邮件服务器,如 smtp.xyz.in 端口25 上使用有效的该域名上的电子邮件ID和密码。

In one application, I implemented mail sending logic using java. I used smtp.gmail.com over 587 port with a valid gmail id and password. In development environment everything is working fine. But in production environment I need to use a different mailing server say smtp.xyz.in over port 25 with a valid email id and password on that domain.

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

When I continue with SSL enable with following code:

我是收到错误

无法将套接字转换为TLS

SunCertPathBuilderException:无法找到要求目标的有效证书路径

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

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

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并尝试添加以下代码时:

When I am removing EnableSSL and trying by adding the following code:

(获取javax.mail.AuthenticationFailedException:535 5.7.3身份验证失败)

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

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

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);

通过google搜索过去3天,我明白我需要配置可信证书,如给定< A HREF = http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/ 相对= nofollow>此处。

By googling enough in last 3 days, I understand that I need to configure for trusted certificate like given here.

但是我希望在没有加密的情况下继续使用,而不是抢先启用SSL。有没有办法通过我们自己的域发送java程序的电子邮件而不启用SSL。
任何帮助将不胜感激。

But I want to continue without encryption and without mugging to enable SSL. Is there a way to send emails by java programs through our own domain without enabling SSL. Any help will be appreciated.

推荐答案

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

Whether SSL/TLS is required or not is controlled by your mail server. If it requires it, you have to use it.

你可以设置mail.smtp.ssl.trust属性忽略证书问题,或者您可以按照JavaMail常见问题解答

You can set the mail.smtp.ssl.trust property to ignore the certificate issue, or you can fix it as described in the JavaMail FAQ.

这篇关于Java Mailing Logic:无法将套接字转换为TLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆