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

balteo picture balteo · Dec 21, 2011 · Viewed 33.8k times · Source

I am trying to send email with Amazon's SES/SMTP and I am getting the following error:

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

Here is how I am trying to send the mail:

Spring mail sender config:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${mail.server}"/>
        <property name="port" value="${mail.port}"/>
        <property name="username" value="${aws.mail.smtp.user}"/>
        <property name="password" value="${aws.mail.smtp.password}"/>
        <property name="javaMailProperties">
            <props>
            <!-- Use SMTP-AUTH to authenticate to SMTP server -->
            <prop key="mail.smtp.auth">true</prop>
            <!-- Use TLS to encrypt communication with SMTP server -->
            <prop key="mail.smtp.starttls.enable">true</prop>  
            </props>    
        </property>
    </bean>

with:

mail.server =email-smtp.us-east-1.amazonaws.com
mail.port = 465

Answer

balteo picture balteo · Dec 24, 2011

With amazon SES, configuration needs to be as follows:

<prop key="mail.smtp.auth">true</prop>    
<prop key="mail.smtp.ssl.enable">true</prop>

instead of:

<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop> 

as hinted by dave.

EDIT: Please use this solution: https://stackoverflow.com/a/8928559/536299