Archived Forum Post

Index of archived forum posts

Question:

Why my session to hotmail ends?

Aug 20 '12 at 17:45

I have this code for opening a connection to a pop3 server (in my case, hotmail

    if (MySession.Current.Pop3 == null)
    {
                    MySession.Current.Pop3 = POP3Utils.GetPop3NewInstance();

                    //login checks
                    if (!POP3Utils.Login(MySession.Current.Pop3, imapAddress.ImapHost, imapAddress.Port, MySession.Current.userEmail, MySession.Current.userPassword))
                    {
                        //threat 15 minutes error usually coming for hotmail users
                        if (MySession.Current.Pop3.LastErrorText.Contains("Exceeded the login limit for a 15 minute period"))
                        {
                            TempData.Add("error", Resources.Resources.ExportPop315MinutesWarning);
                            return RedirectToAction("Retry", "Login");
                        }
                        //incorrect login
                        else
                        {
                            TempData.Add("error", Resources.Resources.ExportInvalidCredentials);
                            return RedirectToAction("Retry", "Login");
                        }
                    }
   }
   else
   {
      POP3Utils.MakeSureSessionIsLive(MySession.Current.Pop3);
   }

   ViewBag.TotalEmails = MySession.Current.Pop3.GetMailboxCount();

As you notice, first time I create a pop3 instance with the unlock code, login and get total emails number from the server.

Well, all works nice but after a few minutes of inactivity, if I try to do another operation (for instance do a filter) POP3Utils.MakeSureSessionIsLive(MySession.Current.Pop3) is called:

 public static void MakeSureSessionIsLive(MailMan mailman)
    {
        bool noop = mailman.Pop3Noop();
        if (!noop)
        {
            mailman.Pop3BeginSession();
            Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(String.Format("Succcesfully REINITIALIZED session for account {0}", mailman.PopUsername)));
        }
    }

and of couse, the noop is false and session is reinitialized. But from here on, each operation returns a NULL bundle. And any other operation I do from here on, when I check if the session is alive it ALWAYS goes and reinit it...

Can you please let me know where I am wrong? If after a few minutes of inactivity the session is re-init, why from there on it always try to reinit it for any operation?

UPDATE: When trying to send first noop after a period of idle (few minutes), I notice this in LastErrorText: ...WSAECONNRESET An existing connection was foribly closed by the remote host...NOOP Failed.

So what I understand from here is that I should not call NOOP when the user is coming back from IDLE but send NOOP continuously (for instance one noop per x seconds). But my question is not: HOW I do this? I cannot use Quartz because I keep current user connection in session which is not available in a quartz job... Is any way Chilkat thought of this issue's workaround?


Answer

Please post the full contents of the LastErrorText captured after calling mailman.Pop3BeginSession (from the code snippet that is within the "if (!noop)" statement. Also, make sure to check the success/failure return value of Pop3BeginSession. You shouldn't assume that it will succeed because anything involving network communications shouldn't assume success.