我目前正在调查James Mail Server并在我的本地计算机上运行实例。我正在尝试使用以下代码发送电子邮件,我将进入下面列出的例外:
public static void send() {
try {
String host = "127.0.0.1";
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.port", "465");
props.put("mail.smtps.ssl.trust", host);
Session mailSession = Session.getInstance(props);
mailSession.setDebug(true);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(frAddress));
InternetAddress[] address = { new InternetAddress(toAddress) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
Transport transport = mailSession.getTransport("smtps");
transport.connect(host, userName, password);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
transport.connect(host, userName, password)
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "127.0.0.1", port 465, isSSL true
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
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:1764)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1523)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at com.spectramd.securemail.bouncycastle.JavaMailTest.send(JavaMailTest.java:50)
at com.spectramd.securemail.bouncycastle.JavaMailTest.main(JavaMailTest.java:24)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:106)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:84)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1742)
... 6 more
我已按照列出的here步骤配置James服务器以SSL启动,并根据步骤添加了虚拟JKS证书。我一直在网上看,但到目前为止,我无法找到解决方案。 Plz帮助。
编辑:
忘记提及,我已成功使用普通SMTP发送邮件,并附带James附带的默认配置。
答案 0 :(得分:2)
嗯,看起来詹姆斯没有正确配置。如果您使用telnet在端口465上连接它,您会得到纯文本响应吗?
此外,您还使用了相当旧版本的JavaMail。您可能希望升级到latest version。