title: Spring - Prevent JavaMailSender from authenticating every time an email is sent
body: <p>I am using JavaMailSender and Spring to send emails.</p>
  
  <p>I instantiate the JavaMailSender load it as a property of the mailer bean and autowire the mailer bean to my controller.</p>
  
  <p>I load it with the following properties:</p>
  
  <pre><code>&lt;bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
      &lt;property name="host" value="smtp.gmail.com" /&gt;
      &lt;property name="port" value="587" /&gt;
      &lt;property name="username" value="email@email.com" /&gt;
      &lt;property name="password" value="password" /&gt;
      &lt;property name="javaMailProperties"&gt;
          &lt;props&gt;
              &lt;prop key="mail.debug"&gt;true&lt;/prop&gt;
              &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt;
              &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
              &lt;prop key="mail.mime.charset"&gt;UTF-8&lt;/prop&gt;
              &lt;prop key="mail.transport.protocol"&gt;smtp&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  
   &lt;bean id="mailer" class="mz.co.crunchtech.vtchill.utils.Mailer"&gt;
          &lt;property name="mailSender" ref="mailSender" /&gt;
          &lt;property name="velocityEngine" ref="velocityEngine"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I pass the <em>mailer</em> object around on my worker threads so every once in a while i get the following error:</p>
  
  <blockquote>
    <p>Exception in thread "taskExecutor-50"
    org.springframework.mail.MailAuthenticationException: Authentication
    failed; nested exception is javax.mail.AuthenticationFailedException:
    454 4.7.0 Too many login attempts, please try again later.
    n8sm185296pgd.31 - gsmtp</p>
  </blockquote>
  
  <p>I went to my logs and found various LOGIN succeeded entries as well:</p>
  
  <p>[root@thikiti ~]# cat /usr/share/apache-tomcat-7.0.73/logs/catalina.out | grep -i 'LOGIN succ' | wc -l
  182</p>
  
  <p>Is there a way to avoid re-authenticating each time an email is sent?</p>