@wendal 还是不行啊,把源码贴上
mail.properties
mail.HostName=smtp.mxhichina.com
mail.SmtpPort=25
mail.UserName=shawnxiaoxiao@aliyun.com
mail.Password=
mail.SSLOnConnect=false
mail.From=shawnxiaoxiao@aliyun.com
mail.charset=UTF-8
mail.js
var ioc = {
conf: {
type: "org.nutz.ioc.impl.PropertiesProxy",
fields: {
paths: ["custom/"]
}
},
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')"}
}
}
};
App.java
public class App {
public static void main(String[] args) throws Exception {
Ioc ioc = new NutIoc(new ComboIocLoader("*js", "ioc/"));
HtmlEmail email = ioc.get(HtmlEmail.class);
email.setSubject("测试NutzBook");
email.setMsg("This is a test mail ... :-)" + System.currentTimeMillis());
email.addTo("2079947408@qq.com");//请务必改成您自己的邮箱啊!!!
email.buildMimeMessage();
email.sendMimeMessage();
}
}
报错
Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.mxhichina.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
at com.shawn.App.main(App.java:28)
Caused by: javax.mail.AuthenticationFailedException: 526 Authentication failure[0]
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
... 1 more
密码没错是我网页登陆阿里云邮箱的密码,已经无语了