我的代码导致STARTTLS错误,我该如何解决?

 收藏

我编写了整个代码,并导入了邮件,激活,com.sun.mail和smtp jar,但是在starttls中仍然给我一个错误,这是错误: javax.mail.MessagingException:需要STARTTLS,但主机不支持STARTTLS,

        boolean sessionDebug=false;

    Properties props=System.getProperties();
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", "465");
    props.put("mail.smtp.auth", "true");

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

    final javax.mail.Session mailSession = javax.mail.Session.getInstance(props);
    java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
   props.put("mail.smtp.debug", "true");

    //Session mailSession=Session.getDefaultInstance(props,null);
    mailSession.setDebug(sessionDebug);
    Message msg = new MimeMessage(mailSession);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address={new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO,address);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    msg.setText(msgText);

    Transport transport =mailSession.getTransport("smtp");
        System.out.println("smtp");

    transport.connect(host,user,pass);
        System.out.println("smtp connection");
    transport.sendMessage(msg,msg.getAllRecipients());
        System.out.println("smtp message");
    transport.close();
回复