我有一个从实时邮件中获取邮件的代码。我的步骤:
- 连接到服务器
- 打开文件夹
- 获取一些信息
- 关闭文件夹
- 关闭商店
但有时我调用这个函数,我从服务器收到消息:
ERR Exceeded the login limit for a 15 minute period. Reduce the frequency of requests to the POP3 server
那么我该如何解决这个问题。我关闭了连接并打开了新的。我没有保持连接所以为什么我得到这个错误
public boolean POPgetMail(final String EMAIL,final String PASS,final String Type,boolean isNewMail) {
int NUMBER_MAIL=5;
Message[] message_s = null;
Properties props2 = System.getProperties();
props2.setProperty("mail.store.protocol", "pop3s");
Session session2 = Session.getInstance(props2, null);
session2.setDebug(true);
try {
Store store = session2.getStore("pop3s");
HOSTGET = "pop3.live.com";
store.connect(HOSTGET,EMAIL,PASS);
Log.i("","Connect Success");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
int new_mail=0;
message_s = folder.getMessages();
int countMail =folder.getMessageCount() -1;
if(countMail<0) {
folder.close(true);
store.close();
return false;
}
Log.i("","Total Mail + "+ countMail);
for (int i =countMail;i > NUMBER_MAIL;i--)
{
Message message = message_s[i];
if(message != null)
{
Log.i("MAIL","LOading Mail ID = " + i);
String subject ="No Subject";
try {
subject=message.getSubject().toString();
}
catch(Exception e)
{
Log.i("XX",e.toString());
}
String contents="";
int ID =i;
Date Date = message.getSentDate();
String date = DatenTime.convertDate(Date);
Address[] froms = message.getFrom();
//get TO
String to="";
try {
Address[] tos = message.getRecipients(Message.RecipientType.TO);
if(tos!=null)
{
for (int j=0;j<tos.length;j++){
to+=((InternetAddress)tos[j]).getAddress() +";";
Log.i("","TOOOOOOOO" + to);
}
}
}
catch (Exception e)
{
Log.i("",e.toString());
}
//get CC
Address[] toCC = message.getRecipients(Message.RecipientType.CC);
String CC="";
if(toCC!=null)
{
for (int j=0;j<toCC.length;j++){
CC+=((InternetAddress)toCC[j]).getAddress() +";";
Log.i("","TOOOOOOOO" + CC);
}
String name = ((InternetAddress) froms[0]).toUnicodeString();
String from = ((InternetAddress) froms[0]).getAddress();
if(mDB.InsertEmailData(ID,EMAIL,name,from,to,CC,contents,subject,date,Define.INBOX)!=-1)
{
System.out.println("get mail success");
}
}
}
folder.close(true);
store.close();
mDB.close();
return true;
} catch (Exception e) {
Log.i("","EX " + e.toString());
return false;
}
}