我原来写过一个,你看看先。
http://expert.csdn.net/Expert/topic/679/679555.xml?temp=.512356尤其是这一段: if(username != null && password != null) {
trans.connect(host, username, password);
msg.saveChanges();
} else {
trans.connect();
}
http://expert.csdn.net/Expert/topic/679/679555.xml?temp=.512356尤其是这一段: if(username != null && password != null) {
trans.connect(host, username, password);
msg.saveChanges();
} else {
trans.connect();
}
难道我真的是RPWT!!我用163.net,163.com,21cn.com都试过了!!!
运行时出现的错误:
DEBUG: SMTPTransport connected to host "smtp.163.com", port: 25
DEBUG SMTP SENT: mail from: <[email protected]>DEBUG SMTP RCVD: 553 You are not authorized to send mail as <mail from: <[email protected]>>, authentication is required
javax.mail.MessagingException: 553 You are not authorized to send mail as <mail from: <[email protected]>>, authentication is required
Session session = Session.getDefaultInstance(props,new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("123","123");
}
tr.connect(smtphost, username, password);
msg.saveChanges(); // don't forget this
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
DEBUG: SMTPTransport trying to connect to host "smtp.163.com", port 25
DEBUG SMTP RCVD: 220 Welcome to coremail System(With Anti-Spam) 2.1 for www.163.com
DEBUG SMTP SENT: helo zhpDEBUG SMTP RCVD: 250 192.168.1.204
DEBUG: SMTPTransport connected to host "smtp.163.com", port: 25
DEBUG SMTP SENT: mail from: <[email protected]>DEBUG SMTP RCVD: 553 You are not authorized to send mail as <mail from: <[email protected]>>, authentication is required
DEBUG SMTP SENT: quit
Session session = Session.getDefaultInstance(props,new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("123","123");
}
});
也不行阿。
刚刚看到一个贴说和DNS设置有关??那DNS该如何设??
无关!因为你都连上了。如果你的ip以被163.net作为“禁止”,那另当别论。用下面的代码测试的码?
Transport tr = session.getTransport("smtp");
tr.connect(smtphost, username, password);
msg.saveChanges(); // don't forget this
提醒一下:
message.saveChanges(); // don't forget this//before you send message
tr.sendMessage(message, message.getAllRecipients());
如:
[email protected]>[email protected]
应该使用:
[email protected]>[email protected] 或
[email protected]>[email protected]
再次感谢 takecare(大厅) 的帮忙。