I have a java Spring web app from which I send emails using my Gmail account credentials. Everything worked fine until I migrated my site from DigitalOcean to AWS EC2. Now when I try to send an email I get the following error:
ERROR SendMailServiceImpl:48 - Error sending mail:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty. Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty; message exceptions (1) are: Failed message 1: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
Here is my mail sender configuration:
<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="myAccount@gmail.com"/>
<property name="password" value="myPassword"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
I have "untrusted applications allowed" enabled in my Gmail account. But I get the same error again and again. Moreover when I lunch my application locally then everything works fine and I don't get any errors
looks like this is some kind of gmail restriction for remote hosts
does anybody know how to fix this?
thank you