无法使用javax.mail在端口25上发送SSL = true的邮件

时间:2018-05-03 14:23:54

标签: email smtp

//以下是我的配置:

Properties properties = System.getProperties(); 
properties.setProperty("mail.smtp.host", host);
properties.put("mail.smtp.port", "25"); 
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true"); 
properties.put("mail.smtp.socketFactory.fallback", "false");
properties.put("mail.smtp.socketFactory.class",javax.net.ssl.SSLSocketFactory"); 

Authenticator auth = new Authenticator() {
                      protected PasswordAuthentication getPasswordAuthentication() {
                         return new PasswordAuthentication("username", "password");
                      }
                     };

 Session session = Session.getInstance(properties, auth);

//我的端口号是25,SSL应该是true。我得到以下异常:

javax.mail.MessagingException: Exception reading response;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1090)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:986)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
    at javax.mail.Service.connect(Service.java:233)

0 个答案:

没有答案