我面临一个奇怪的问题,尝试在mail.ru上使用JavaMail,但它并没有给我新的电子邮件。我登录,每秒开始检查getMessages(),手动发送电子邮件,但getMessages()总是返回我发送之前的相同电子邮件。换句话说,它不会提供任何超过登录邮箱的新电子邮件。我错过了什么?这是完整的代码:
public class MailboxReader
{
private Store store;
private Folder inbox;
public MailboxReader(EmailAcc emailAcc)
{
// connect to pop3 inbox
try {
Properties properties = System.getProperties();
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
properties.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.pop3.socketFactory.fallback", "false");
properties.setProperty("mail.pop3.port", String.valueOf(emailAcc.pop3port));
properties.setProperty("mail.pop3.socketFactory.port", String.valueOf(emailAcc.pop3port));
properties.setProperty("mail.pop3.ssl.trust", "*");
Session session = Session.getInstance(properties);
store = session.getStore("pop3");
store.connect(emailAcc.pop3ip, emailAcc.pop3port, emailAcc.username, emailAcc.password);
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
} catch(Exception e)
{
e.printStackTrace();
}
}
public Message[] getMessages()
{
try {
return inbox.getMessages();
} catch (MessagingException e) {
e.printStackTrace();
}
return null;
}
public void close()
{
try {
inbox.close(true);
store.close();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
我已手动登录收件人的电子邮件帐户,以检查我的电子邮件是否到达 - 确实如此。而且,如果我使用JavaMail重新连接到邮箱,它也会看到它。但是每一秒都要重新连接是愚蠢的,其他的是错误的。