I am trying to find the correct properties to use to connect to the Gmail SMTP sever using the JavaMailSenderImpl class.
Let me first say that I have tried the approach found here. This worked fine. But when I tried the configuration below that post with the exact same authentication information I received a javax.mail.AuthenticationFailedException.
My currently configuration looks like this.
<bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" > <property name="username" value="[email protected]" /> <property name="password" value="XXX" /> <property name="javaMailProperties"> <props> <prop key="mail.smtp.host">smtp.gmail.com</prop> <prop key="mail.smtp.port">587</prop> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> </props> </property> </bean>
Why am I still getting this javax.mail.AuthenticationFailedException if I know that my credentials are correct.
Here is my updated code based on the answers below. I am still receiving the same exception.
<bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" > <property name="username" value="[email protected]" /> <property name="password" value="XXX" /> <property name="javaMailProperties"> <props> <prop key="mail.smtp.from">[email protected]</prop> <prop key="mail.smtp.user">[email protected]</prop> <prop key="mail.smtp.password">XXX</prop> <prop key="mail.smtp.host">smtp.gmail.com</prop> <prop key="mail.smtp.port">587</prop> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> </props> </property> </bean>
You need to use Scheduler in your spring boot application to schedule your email task. The Spring Framework provides abstractions for asynchronous execution and scheduling of tasks with the TaskExecutor and TaskScheduler interfaces, respectively.
This worked for me:
<property name="host"><value>smtp.gmail.com</value></property> <property name="port"><value>587</value></property> <property name="protocol"><value>smtp</value></property> <property name="username"><value>${mail.username}</value></property> <property name="password"><value>${mail.password}</value></property> <property name="javaMailProperties"> <props> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> <prop key="mail.smtp.quitwait">false</prop> </props> </property>
The real trick for me turned out to be that the "protocol" value has to be "smtp" (not "smtps").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With