SSLException:java.security.InvalidAlgorithmParameterException:trustAnchors参数必须为非空

时间:2019-01-11 21:08:04

标签: java

你好,我在eclipse下执行代码时遇到问题。 我在其他机器上尝试过,然后将代码发送给朋友,并且在他的机器上运行正常

代码:

 public EnvoyerMail(String receiverEmailID, String emailSubject, String emailBody) {
    System.setProperty("javax.net.ssl.trustStore", "C:/.keystore");
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    this.receiverEmailID = receiverEmailID;
    this.emailSubject = emailSubject;
    this.emailBody = emailBody;
    Properties properties = new Properties();
    properties.put("mail.smtp.user", senderEmailID);
    properties.put("mail.smtp.host", emailSMTPserver);
    properties.put("mail.smtp.port", emailServerPort);
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.debug", "true");
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.ssl.enable", "true");
    properties.put("mail.smtp.socketFactory.port", emailServerPort);
    properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    properties.put("mail.smtp.socketFactory.fallback", "false");

    SecurityManager security = System.getSecurityManager();

    try {
        Authenticator auth = new SMTPAuthenticator();
        Session session = Session.getInstance(properties,auth);
        session.setDebug(true);
        MimeMessage msg = new MimeMessage(session);
        msg.setText(emailBody);
        msg.setSubject(emailSubject);
        msg.setFrom(new InternetAddress(senderEmailID));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(receiverEmailID));

        Transport.send(msg);
        System.out.println("Message Send");
    }catch(Exception e) {
        e.printStackTrace();
    }
}
    public class SMTPAuthenticator extends javax.mail.Authenticator{
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(senderEmailID, senderPassword);
        }
    }

这是我得到的错误:

javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

0 个答案:

没有答案