How to configure Spring JavaMailSender for SES using SMTP?

rreyes1979 picture rreyes1979 · Jan 18, 2012 · Viewed 29.9k times · Source

We are trying to configure Spring JavaMailSender to work with Amazon's SES service using SMTP, but we are getting this error:

javax.mail.MessagingException: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 465, response: -1

This is our configuration:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="email-smtp.us-east-1.amazonaws.com" />
    <property name="port" value="465" />
    <property name="username" value="..." />
    <property name="password" value="..." />
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.ssl.enable">true</prop>
        </props>
    </property>
</bean>

Any ideas what could be wrong? Thanks in advance.

PS: We already tried the solution here: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 465, response: -1 without any luck.

Answer

rreyes1979 picture rreyes1979 · Jan 19, 2012

Based on @GuCo answer: This is the full configuration that worked for me:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="email-smtp.us-east-1.amazonaws.com" />
    <property name="port" value="465" />
    <property name="protocol" value="smtps" />
    <property name="username" value="..." />
    <property name="password" value="..." />
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtps.auth">true</prop>
            <prop key="mail.smtp.ssl.enable">true</prop>
            <prop key="mail.transport.protocol">smtps</prop>
        </props>
    </property>
</bean>

Do not forget the <property name="protocol" value="smtps" /> configuration, or else the javaMailProperties are not taken into consideration.