0

我正在开发一个 java 邮件客户端:

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class MailClient {
    public static void main(String[] args) {
        try {
            Properties props = new Properties();
            Session session;

            URLName url = new URLName("pop3","pop.gmail.com",995,"","email@gmail.com","password");
            session = Session.getInstance(props, null);
            Store store = new POP3SSLStore(session,url);
            store.connect();

            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(message[i].getSubject());
            }
            folder.close(false);
            store.close();
        }
        catch (MessagingException e) {
            System.out.println("Error: " + e);
        }
    }
}

发生的错误是这样的:

MailClient.java:13: error: cannot find symbol
Store store = new POP3SSLStore(session,url);
symbol: class POP3SSLStore
location: class MailClient
1 error
4

2 回答 2

1

您缺少导入:

import com.sun.mail.pop3.POP3SSLStore;

之后它应该编译

于 2012-10-19T04:16:21.527 回答
1

您不应该自己实例化 Store 对象。让 Session 为你做这件事。调用 session.getStore("pop3s")。请参阅JavaMail 下载包中包含的示例代码,以及JavaMail FAQ中的示例,尤其是Gmail 示例

于 2012-10-19T06:30:12.917 回答