Sha*_*ena 5 java smtp jakarta-mail mailing
在一个应用程序中,我使用java实现了邮件发送逻辑.我用smtp.gmail.com了587 port一个有效的Gmail密码和密码.在开发环境中,一切正常.但是,在生产环境中,我需要使用不同的邮件服务器说,smtp.xyz.in在port 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);
Run Code Online (Sandbox Code Playgroud)
当我删除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);
Run Code Online (Sandbox Code Playgroud)
通过google搜索过去3天,我明白我需要配置像这里给出的可信证书.
但我想继续没有加密,也没有抢劫启用SSL.有没有办法通过我们自己的域发送java程序的电子邮件而不启用SSL.任何帮助将不胜感激.
Bil*_*non 10
是否需要SSL/TLS由您的邮件服务器控制.如果需要,你必须使用它.
您可以设置mail.smtp.ssl.trust属性以忽略证书问题,也可以按照JavaMail FAQ中的说明进行修复.