Question

I have a code to get mail from live mail. My step :

  • Connect to sever
  • Open folder
  • Get some informations
  • Close folder
  • Close store

But sometime I call this function, I got message from sever :

 ERR Exceeded the login limit for a 15 minute period. Reduce the frequency of requests to the POP3 server

So How do I slove this problem. I closed connection and open new. I didnt keep connnection so why I got this error

    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;
                }   
}
Was it helpful?

Solution

I guess you didn't understand the error message. It's not that you kept the connection open for too long, it's that you made too many separate connections in a 15 minute period. Don't connect so often.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top