我正在开发一个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
答案 0 :(得分:1)
您缺少导入:
import com.sun.mail.pop3.POP3SSLStore;
之后应该编译
答案 1 :(得分:1)
您不应该自己实例化Store对象。让Session为你做。调用session.getStore(“pop3s”)。请参阅JavaMail download bundle附带的示例代码以及JavaMail FAQ中的示例,尤其是Gmail example。