AuthenticationFailedException: AUTHENTICATE failed After some connections
<p>I have a <code>Spring-Boot (1.4.0)</code> application and I am using <code>springframework.boot:spring-boot-starter-mail</code>.</p>

<p>I have a method annotated with <code>@Scheduled</code> to check my inbox every a certain period of time.</p>

<p>This is how I get my inbox:</p>

<pre><code>private static Folder getInbox() throws MessagingException {
final String protocol = "mail.store.protocol";
        final String storeType = "imaps";
        final String email = "email";
        final String password = "password";
        final String connect = "webmail.company.com";
        final String folder = "INBOX";

        final Properties props = new Properties();
        props.setProperty(protocol, storeType);

        final Session session = Session.getInstance(props, null);
        final Store store = session.getStore();
        store.connect(connect, email, password);

        final Folder inbox = store.getFolder(folder);
        inbox.open(Folder.READ_WRITE);
        return inbox;
    }
</code></pre>

<p>Then I have this:</p>

<pre><code>@Scheduled(fixedRate = 10000)
    @Override
    public void checkEmailCreateCompanyAndSendCsv() throws MessagingException, IOException {
    log.info("Checking e-mail...");
            final Folder inbox = getInbox();

            final Flags seen = new Flags(Flags.Flag.SEEN);
            final FlagTerm unseenFlagTerm = new FlagTerm(seen, false);

            inbox.getMessages();
            final Message messages[] = inbox.search(unseenFlagTerm);


.....
.....
}
</code></pre>

<p>When the APP is running everything works great but after some time (around 7 to 8 e-mail checks) it starts to thrown an exception:</p>

<blockquote>
  <p>javax.mail.AuthenticationFailedException: AUTHENTICATE failed.    at
  com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:717)   at
  javax.mail.Service.connect(Service.java:366)  at
  javax.mail.Service.connect(Service.java:246)  at
  com.opessoftware.crs.selfcertification.services.EmailServiceBasic.getInbox(EmailServiceBasic.java:183)
    at
  com.opessoftware.crs.selfcertification.services.EmailServiceBasic.checkEmailCreateCompanyAndSendCsv(EmailServiceBasic.java:50)
    at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)     at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)     at
  org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at
  org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at
  java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at
  java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at
  java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)</p>
</blockquote>

<p>If I stop the application and run it again the error disappears and the cicle starts again. </p>

<p>Any suggestions?</p>