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

my code results an error with STARTTLS how can i solve it?

我编写了整个代码并导入了邮件、激活、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();

如果您的邮件服务器不支持 STARTTLS,您将无法使用它。请尝试设置 mail.smtp.ssl.enable

此外,修复所有这些 common JavaMail mistakes