Email 无法使用javax.mail在端口25上发送SSL=true的邮件
//以下是我的配置:Email 无法使用javax.mail在端口25上发送SSL=true的邮件,email,smtp,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
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)
您确定此主机在端口25上接受SSL吗?它也在收听587吗?这可能是一个通过STARTTLS支持机会主义SSL的服务器,在这种情况下,聊天以明文开始,然后可以提升到TLS。另外,检查JavaMail文档。您可以在传输级别进行调试,这将为您提供所有SSL聊天详细信息。我们在VB6.0中提供了发送邮件的简单测试应用程序。在带有端口25和SSL true的VB测试应用程序中,它成功发送电子邮件。然后您需要使用JavaMail中的说明调试传输。