I am using JavaMailSender and Spring to send emails.
I instantiate the JavaMailSender load it as a property of the mailer bean and autowire the mailer bean to my controller.
I load it with the following properties:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="587" />
<property name="username" value="email@email.com" />
<property name="password" value="password" />
<property name="javaMailProperties">
<props>
<prop key="mail.debug">true</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.mime.charset">UTF-8</prop>
<prop key="mail.transport.protocol">smtp</prop>
</props>
</property>
</bean>
<bean id="mailer" class="mz.co.crunchtech.vtchill.utils.Mailer">
<property name="mailSender" ref="mailSender" />
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
I pass the mailer object around on my worker threads so every once in a while i get the following error:
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
I went to my logs and found various LOGIN succeeded entries as well:
[root@thikiti ~]# cat /usr/share/apache-tomcat-7.0.73/logs/catalina.out | grep -i 'LOGIN succ' | wc -l 182
Is there a way to avoid re-authenticating each time an email is sent?