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
Note that the AWS note at https://forums.aws.amazon.com/message.jspa?messageID=218303 refers to encrypting server-to-server communication to maintain confidentiality of the email message, is a shared characteristic of all SMTP services.
This question relates to using a secure connection to the AWS SMTP server to protect the passwords used to authenticate with the AWS server.
This employee from AWS states that SES does not support SSL at all. https://forums.aws.amazon.com/message.jspa?messageID=218303 .
Hence, I am thinking the issue you are seeing is not TLS or SSL related, rather something else.
These code have been tested, works fine well. If you want use SMTP over SSL, please config:
Or you can download AWS Java SDK from HERE.
Code sample is HERE
Amazon SES SMTP requires the SSL before the SMTP session. The StartTLS command is not supported by SES.
With amazon SES, configuration needs to be as follows:
instead of:
as hinted by dave.
EDIT: Please use this solution: https://stackoverflow.com/a/8928559/536299
These settings worked for me:
If you try to connect to connect using SSL connection, it rejected the connection. So you need to do STARTTLS after connection.
You can add mail.debug=true to see where it failed.
The sender email address must be a verified email address otherwise SES refuses to forward the email.