title: Mail listener ocassionally fails to authenticate
body: <p><strong>The Problem:</strong></p>
  
  <p>We have multiple tests where we need to actually check the test user's email as a test case step. This is used for two factor authentication and email notification tests.</p>
  
  <p>At the moment, we use the solution provided <a href="https://stackoverflow.com/a/29382990/771848">here</a> which is based on the <a href="https://www.npmjs.com/package/mail-listener2" rel="nofollow noreferrer"><code>mail-listener2</code> node package</a>. Here is the configuration that we use:</p>
  
  <pre><code>email: {
      username: "user email here",
      password: "user password here",
      host: "smtp server address here",
      port: 993,
      tls: true,
      mailbox: "Inbox",
      markSeen: true
  },
  </code></pre>
  
  <p>We initialize the mail listener in the Protractor config inside the <code>onPrepare()</code> function:</p>
  
  <pre><code>var MailListener = require("mail-listener2");
  var mailListener = new MailListener(config.email);
  
  mailListener.start();
  
  mailListener.on("server:connected", function(){
      console.log("Mail listener initialized");
  });
  
  global.mailListener = mailListener;
  </code></pre>
  
  <p>The problem is - in about 10% of the times, the mail listener fails with the following error message:</p>
  
  <blockquote>
    <p>Timed out while authenticating with server </p>
  </blockquote>
  
  <p><strong>The Question:</strong></p>
  
  <p>What can cause the problem and what can we do to make the mail listener work? Also, would it be possible to retry authenticating on a failure?</p>