上面的问题 我用163 的接受邮件 不会报错 但是用sina 的就报上面的错了 我以为是验证的问题 就又写了Authenticator的验证 但是却显示乱码 郁闷 哪位 高手 帮个忙 解决一下啊?
这是源码:
package edu.accp.md.mail.getmail;import java.util.Properties;import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;public class ReciveMail { /**
 * @param args
 */
public static void main(String[] args) {
try {
login("pop3.sina.com.cn", "zidan_cd", "*********");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } public static void login(String host, final String userName, final String pwd)
throws Exception {
// create props
Properties props = new Properties();
// create session

//  SmtpAuth sa = new SmtpAuth(); 
//       sa.setUserInfo(userName, pwd); 
      props.put("mail.smtp.auth", "true");
//       props.setProperty("mail.smtp.auth", "true");
//       Session session = Session.getDefaultInstance(props);
Session session = Session.getDefaultInstance(props, new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(userName,pwd); 
}
});
session.setDebug(true);
// host = new String(host.getBytes("utf-8"));
// create store
Store store = session.getStore("pop3");
System.out.println(host);
store.connect(host, userName, pwd);

// Get Folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get Messages
Message message[] = folder.getMessages();
System.out.println("Message Count:==" + folder.getMessageCount()); for (int i = 0; i < message.length; i++) {
System.out.println("消息主题:" + message[i].getSubject()
+ "/n + 消息发送人:" + message[i].getFrom()[0]);
}
folder.close(false);
store.close();
}}
 
没有验证报错:
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
pop3.sina.com.cn
DEBUG POP3: connecting to host "pop3.sina.com.cn", port 110, isSSL false
S: EOF
javax.mail.AuthenticationFailedException: EOF on socket
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:158)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at edu.accp.md.mail.getmail.ReciveMail.login(ReciveMail.java:48)
at edu.accp.md.mail.getmail.ReciveMail.main(ReciveMail.java:19)
验证后报错:DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
pop3.sina.com.cn
DEBUG POP3: connecting to host "pop3.sina.com.cn", port 110, isSSL false
S: +OK pop3 proxy server ready
C: USER zidan_cd
S: +OK
C: PASS zq370058804
S: -ERR ÎÞ·¨µÇ½£¬ÓÊÏäÃû/ÃÜÂëÊäÈë´íÎó£¬ÊÕ·ÑÓÊÏäÇë¼ì²éÊÇ·ñ¹ýÆÚ - authorization failed
C: QUIT
S: EOF
DEBUG POP3: connecting to host "pop3.sina.com.cn", port 110, isSSL false
S: EOF
javax.mail.AuthenticationFailedException: EOF on socket
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:158)
at javax.mail.Service.connect(Service.java:313)
at javax.mail.Service.connect(Service.java:172)
at edu.accp.md.mail.getmail.ReciveMail.login(ReciveMail.java:48)
at edu.accp.md.mail.getmail.ReciveMail.main(ReciveMail.java:19)

解决方案 »

  1.   

    DEBUG POP3: connecting to host "smtp.qq.com", port 110, isSSL false
    S: EOF
    DEBUG POP3: connecting to host "smtp.qq.com", port 110, isSSL false
    S: EOF
    Exception in thread "main" javax.mail.AuthenticationFailedException: EOF on socket
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)
    at javax.mail.Service.connect(Service.java:297)
    at javax.mail.Service.connect(Service.java:156)
    at com.viays.mail.client.GetEmail.connect(GetEmail.java:117)
    at com.viays.mail.client.GetEmail.getAllmail(GetEmail.java:124)
    at com.viays.mail.client.GetEmail.main(GetEmail.java:246)
    这是我用QQ邮箱的时候出的错误
    -----------------------------------------------
    EBUG POP3: connecting to host "exchangeserver", port 110, isSSL false
    S: +OK The Microsoft Exchange POP3 service is ready.
    C: USER [email protected]
    S: -ERR Command is not valid in this state.
    C: QUIT
    S: +OK Microsoft Exchange Server 2007 POP3 server signing off.
    DEBUG POP3: connecting to host "exchangeserver", port 110, isSSL false
    S: +OK The Microsoft Exchange POP3 service is ready.
    C: USER [email protected]
    S: -ERR Command is not valid in this state.
    C: QUIT
    S: +OK Microsoft Exchange Server 2007 POP3 server signing off.
    Exception in thread "main" javax.mail.AuthenticationFailedException: Command is not valid in this state.
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)
    at javax.mail.Service.connect(Service.java:297)
    at javax.mail.Service.connect(Service.java:156)
    at com.viays.mail.client.GetEmail.connect(GetEmail.java:117)
    at com.viays.mail.client.GetEmail.getAllmail(GetEmail.java:124)
    at com.viays.mail.client.GetEmail.main(GetEmail.java:253)
    有exchange是的错误
      

  2.   

    试一下 store.connect("mail.163.com", userName, pwd);  
    主要是HOSTNAME多试几个,或者写成pop3.163.com