dao.js:
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : [ "custom/" ]
}
},
mail.properties:
mail.HostName=smtp.qq.com
mail.SmtpPort=587
mail.UserName=2079947408@qq.com
mail.Password=**********
mail.SSLOnConnect=true
mail.From=2079947408@qq.com
mail.charset=UTF-8
密码为独立密码!
mail.js:
var ioc = {
emailAuthenticator : {
type : "org.apache.commons.mail.DefaultAuthenticator",
args : [ {
java : "$conf.get('mail.UserName')"
}, {
java : "$conf.get('mail.Password')"
} ]
},
htmlEmail : {
type : "org.apache.commons.mail.ImageHtmlEmail",
singleton : false,
fields : {
hostName : {
java : "$conf.get('mail.HostName')"
},
smtpPort : {
java : "$conf.get('mail.SmtpPort')"
},
authenticator : {
refer : "emailAuthenticator"
},
SSLOnConnect : {
java : "$conf.get('mail.SSLOnConnect')"
},
from : {
java : "$conf.get('mail.From')"
},
charset : {
java : "$conf.get('mail.charset', 'UTF-8')"
}
}
}
};
MainSetup类的init方法末尾:
try {
HtmlEmail email = ioc.get(HtmlEmail.class);
email.setSubject("测试NutzBook");
email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
email.addTo("shawn_xiao@supercluster.cn");//请务必改成您自己的邮箱啊!!!
email.buildMimeMessage();
email.sendMimeMessage();
} catch (Exception e) {
e.printStackTrace();
}
报错:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.qq.com:465
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
at net.wendal.nutzbook.MainSetup.init(MainSetup.java:47)
at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
at net.wendal.nutzbook.mvc.NutzBookNutFilter.init(NutzBookNutFilter.java:20)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4561)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5203)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2055)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
... 19 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:348)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
... 26 more
求解惑