0

尝试使用 JavaMail 阅读邮件时出现此错误。请让我知道如何解决此错误。我已将activation.jarmail.jar添加到eclipse 中。

DEBUG POP3: server doesn't support TOP, disabling it
javax.mail.AuthenticationFailedException: Command is not valid in this state.
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:174)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at library.VerifyEmail.main(VerifyEmail.java:40)

下面是我正在尝试的代码:

package library;

import java.io.IOException;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import com.sun.mail.pop3.POP3Store;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.search.SubjectTerm;
import javax.activation.*;
import java.io.*;
public class VerifyEmail {
public static void main(String[] args) throws Exception {
     // SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!!
    String host = "myhost";
    // SUBSTITUTE YOUR USERNAME AND PASSWORD TO ACCESS E-MAIL HERE!!!
    String user = "myuser";
    String password = "mypass";

 // Get a session.  Use a blank Properties object.
    Session session = Session.getInstance(new Properties());
    try {
        // Get a Store object
        Store store = session.getStore("pop3");
        store.connect(host, user, password);

        // Get "INBOX"
        Folder fldr = store.getFolder("INBOX");
        fldr.open(Folder.READ_WRITE);
        int count = fldr.getMessageCount();
        System.out.println(count  + " total messages");

        // Message numebers start at 1
        for(int i = 1; i <= count; i++) {
            // Get  a message by its sequence number
            Message m = fldr.getMessage(i);
         // Get some headers
            Date date = m.getSentDate();
            Address [] from = m.getFrom();
            String subj = m.getSubject();
            String mimeType = m.getContentType();
            System.out.println(date + "\t" + from[0] + "\t" +
                                subj + "\t" + mimeType);
        }

    }catch (MessagingException  ioex) {
        ioex.printStackTrace();
    }
}
}
4

3 回答 3

3

当您收到javax.mail.AuthenticationException时,这意味着您的应用程序无法对邮件服务器进行身份验证。

一个可能的原因可能是客户端密钥库中缺少邮件服务器的 SSL 证书。

于 2015-08-05T07:48:48.293 回答
0

According to microsoft: For exchange 2010, by default, the server would need the client use ssl for pop3. Without ssl the server responds with "ERR command is not valid in this state."

Here's how to use javamail with ssl - Javamail and Gmail Pop3 SSL

于 2013-02-25T07:13:41.290 回答
0

DEBUG POP3:服务器不支持 TOP,禁用它 可以通过将 java 邮件 jar 版本更新为 1.4.4 来禁用此消息

于 2013-08-14T10:16:32.477 回答