当前位置: 技术问答>java相关
高分:為什麼用smtp.163.net服務器,不能發給smtp.163.com的郵箱用戶,要怎麼做才行
来源: 互联网 发布时间:2015-05-11
本文导语: 我用smtp.163.net服務器能發給xxx@163.net的郵箱, 發給xxx@163.com的用戶卻出錯: javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.SendFailedException: Invalid Addresses; nested exception is: javax.mail.SendFailedEx...
我用smtp.163.net服務器能發給xxx@163.net的郵箱,
發給xxx@163.com的用戶卻出錯:
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 : Invalid User
請高手指點迷津。
發給xxx@163.com的用戶卻出錯:
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 : Invalid User
請高手指點迷津。
|
那是因为163.net需要用户身份验证,一下是一个例子:
Properties prop = new Properties();
prop.setProperty("mail.transport.protocol","smtp");
prop.setProperty("mail.smtp.host","smtp.163.net");
prop.setProperty("mail.smtp.auth","true");
Session session = Session.getInstance(prop,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("YourUserNameIn163.net","YourPassword");
}
});
Transport trans = session.getTransport();
//sendmessage
trans.close();
Properties prop = new Properties();
prop.setProperty("mail.transport.protocol","smtp");
prop.setProperty("mail.smtp.host","smtp.163.net");
prop.setProperty("mail.smtp.auth","true");
Session session = Session.getInstance(prop,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("YourUserNameIn163.net","YourPassword");
}
});
Transport trans = session.getTransport();
//sendmessage
trans.close();