james下接收邮件错误
我在james中注册的用户名是admin,密码是admin。为什么运行接收邮件报Authentication failed错误,已经找了好久的原因,一直没解决,邮件系统继续不下去了。望高手予以解答。谢谢。完整代码如下:
public class ReceiveMail {
public static void getMail(){
String host = "localhost";
final String username = "admin";
final String password = "admin";
// 创建Properties 对象
Properties props = new Properties();
// 创建邮件会话
Session session = Session.getDefaultInstance(props, new Authenticator(){
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
// 获取邮箱的pop3存储
Store store = session.getStore("pop3");
store.connect(host, username, password);
// 获取inbox文件
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY); //打开,打开后才能读取邮件信息
// 获取邮件消息
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++) {
System.out.println(i + ": " + message[i].getFrom()[0]
+ "\t" + message[i].getSubject());
try {
message[i].writeTo(System.out);
} catch (IOException e) {
e.printStackTrace();
}
}
// 关闭资源
folder.close(false);
store.close();
} catch (MessagingException e) {
e.printStackTrace();
}
System.out.println("GetMail Process Over!");
}
public static void main(String[] args) {
ReceiveMail.getMail();
}
}