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

在一个应用程序中,我使用java实现了邮件发送逻辑。 我使用smtp.gmail.com超过587 port ,使用有效的Gmail密码和密码。 在开发环境中,一切正常。 但是在生产环境中,我需要使用不同的邮件服务器,例如通过port 25 smtp.xyz.in ,并在该域上使用有效的电子邮件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); 

通过google搜索过去3天,我明白我需要配置像这里给出的可信证书。

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

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

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

通常,您需要指定的只是您的SMTP服务器主机,端口以及您的SMTP服务器是否需要在发送电子邮件时进行身份validation,以及是否应通过SSL / TLS保护与SMTP服务器的通信。 您需要正确指定相应的属性,就是这样。

但是,上述参数由SMTP服务器决定。 服务器决定是否只接受安全连接; 以及它是否应该使用SSL或更安全的TLS,它们可能是其中之一,也可能是两者兼而有之。 此外,某些SMTP服务器在发送电子邮件时确实需要发件人身份validation,而有些则不需要。 因此,您需要检查要用于正确配置参数的SMTP服务器的文档。 有关使用Gmail发送电子邮件的工作示例,请参阅此处

如果你正在使用

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

请删除此代码段以避免SMTP服务器的SSL配置。

嘿取消激活你的防病毒function。

我在防病毒软件中仅停用SMTP出站